diff options
| author | Roman Smrž <roman.smrz@seznam.cz> | 2026-10-17 11:10:40 +0200 |
|---|---|---|
| committer | Roman Smrž <roman.smrz@seznam.cz> | 2026-10-20 20:21:44 +0200 |
| commit | 5f892bc3cd212f362b0a8f29528b783b142da8e8 (patch) | |
| tree | a345cab6908eb72632684be751caf0ea1c793f1c /src/Main.hs | |
| parent | db6cd2706417d38b670438475c30a657ce2e5ed4 (diff) | |
Config option to find tool path using cabal
Changelog: Added config file option to find test tool executable via cabal.
Diffstat (limited to 'src/Main.hs')
| -rw-r--r-- | src/Main.hs | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/src/Main.hs b/src/Main.hs index 3bc9e22..fc91b56 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -66,9 +66,9 @@ data TcpdumpOption options :: [ OptDescr (CmdlineOptions -> CmdlineOptions) ] options = [ Option ['T'] ["tool"] - (ReqArg (\str -> to $ \opts -> case break (==':') str of - (path, []) -> opts { optDefaultTool = path } - (pname, (_:path)) -> opts { optProcTools = (ProcName (T.pack pname), path) : optProcTools opts } + (ReqArg (\str -> to $ \opts -> case break (== ':') str of + ( path, [] ) -> opts { optDefaultTool = ToolPath path } + ( pname, _ : path ) -> opts { optProcTools = ( ProcName (T.pack pname), ToolPath path ) : optProcTools opts } ) "<path>") "test tool to be used" , Option ['v'] ["verbose"] @@ -140,8 +140,14 @@ main = do config <- mapM parseConfig =<< findConfig let baseDir = maybe "." configDir config - envtool <- lookupEnv "EREBOS_TEST_TOOL" >>= \mbtool -> - return $ fromMaybe (error "No test tool defined") $ mbtool `mplus` (return . (baseDir </>) =<< configTool =<< config) + envtool <- lookupEnv "EREBOS_TEST_TOOL" >>= \mbtool -> if + | Just envpath <- mbtool + -> return $ ToolPath envpath + | Just conftool <- configTool =<< config + -> case conftool of + ToolPath cpath -> return $ ToolPath $ baseDir </> cpath + ToolCabal ccabal -> return $ ToolCabal ccabal + | otherwise -> return $ error "No test tool defined" let initOpts = defaultCmdlineOptions { optTest = defaultTestOptions @@ -183,11 +189,13 @@ main = do testMode config exitSuccess - case words $ optDefaultTool $ optTest opts of - (path : _) -> getPermissions path >>= \perms -> do - when (not $ executable perms) $ do - fail $ "‘" <> path <> "’ is not executable" - _ -> fail $ "invalid tool argument: ‘" <> optDefaultTool (optTest opts) <> "’" + case optDefaultTool $ optTest opts of + ToolPath tpath -> case words tpath of + (path : _) -> getPermissions path >>= \perms -> do + when (not $ executable perms) $ do + fail $ "‘" <> path <> "’ is not executable" + _ -> fail $ "invalid tool argument: ‘" <> tpath <> "’" + ToolCabal _ -> return () files <- if not (null ofiles) then return $ flip map ofiles $ \ofile -> |