diff options
author | Roman Smrž <roman.smrz@seznam.cz> | 2023-01-03 22:56:57 +0100 |
---|---|---|
committer | Roman Smrž <roman.smrz@seznam.cz> | 2023-01-03 22:56:57 +0100 |
commit | 433c3f0a80784a5e529b9268891ed2fddf0f2627 (patch) | |
tree | 4ab1da9b78442f744becc891d152cc208724a231 | |
parent | 1a5670d0fc6ee4640fc84b5abc01bf5efd85f5ce (diff) |
Command-line option to display version
-rw-r--r-- | erebos-tester.cabal | 1 | ||||
-rw-r--r-- | src/Main.hs | 12 |
2 files changed, 13 insertions, 0 deletions
diff --git a/erebos-tester.cabal b/erebos-tester.cabal index 47c3639..1819223 100644 --- a/erebos-tester.cabal +++ b/erebos-tester.cabal @@ -38,6 +38,7 @@ executable erebos-tester-core Network Output Parser + Paths_erebos_tester Process Run.Monad Test diff --git a/src/Main.hs b/src/Main.hs index 98fa9f1..e90aa79 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -28,6 +28,9 @@ import System.Posix.Process import System.Posix.Signals import System.Process +import Paths_erebos_tester (version) +import Data.Version (showVersion) + import Config import GDB import Network @@ -337,12 +340,14 @@ runTest out opts test = do data CmdlineOptions = CmdlineOptions { optTest :: TestOptions + , optShowVersion :: Bool , optVerbose :: Bool } defaultCmdlineOptions :: CmdlineOptions defaultCmdlineOptions = CmdlineOptions { optTest = defaultTestOptions + , optShowVersion = False , optVerbose = False } @@ -368,6 +373,9 @@ options = , Option ['f'] ["force"] (NoArg $ to $ \opts -> opts { optForce = True }) "remove test directory if it exists instead of stopping" + , Option ['V'] ["version"] + (NoArg $ \opts -> opts { optShowVersion = True }) + "show version and exit" ] where to f opts = opts { optTest = f (optTest opts) } @@ -394,6 +402,10 @@ main = do (_, _, errs) -> ioError (userError (concat errs ++ usageInfo header options)) where header = "Usage: erebos-tester [OPTION...]" + when (optShowVersion opts) $ do + putStrLn $ "Erebos Tester version " <> showVersion version + exitSuccess + getPermissions (head $ words $ optDefaultTool $ optTest opts) >>= \perms -> do when (not $ executable perms) $ do fail $ optDefaultTool (optTest opts) <> " is not executable" |