From 433c3f0a80784a5e529b9268891ed2fddf0f2627 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Tue, 3 Jan 2023 22:56:57 +0100 Subject: Command-line option to display version --- src/Main.hs | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src') 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" -- cgit v1.2.3