summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoman Smrž <roman.smrz@seznam.cz>2024-04-24 21:11:31 +0200
committerRoman Smrž <roman.smrz@seznam.cz>2024-04-24 21:11:31 +0200
commit0293f31cb8b96a9b705f7cbba3bd26b58f2e89e2 (patch)
tree90b22c712f2ea1f55b550f41f67dec348009a061
parentc400e22127503aad8b8d4ff10fc3b18a2938fe8e (diff)
Show usage info only with explicit `--help' option
-rw-r--r--src/Main.hs26
1 files changed, 19 insertions, 7 deletions
diff --git a/src/Main.hs b/src/Main.hs
index fee776f..113f54b 100644
--- a/src/Main.hs
+++ b/src/Main.hs
@@ -13,6 +13,7 @@ import System.Environment
import System.Exit
import System.FilePath
import System.FilePath.Glob
+import System.IO
import Config
import Output
@@ -26,16 +27,18 @@ import Version
data CmdlineOptions = CmdlineOptions
{ optTest :: TestOptions
, optRepeat :: Int
- , optShowVersion :: Bool
, optVerbose :: Bool
+ , optShowHelp :: Bool
+ , optShowVersion :: Bool
}
defaultCmdlineOptions :: CmdlineOptions
defaultCmdlineOptions = CmdlineOptions
{ optTest = defaultTestOptions
, optRepeat = 1
- , optShowVersion = False
, optVerbose = False
+ , optShowHelp = False
+ , optShowVersion = False
}
options :: [OptDescr (CmdlineOptions -> CmdlineOptions)]
@@ -66,12 +69,15 @@ options =
, Option ['r'] ["repeat"]
(ReqArg (\str opts -> opts { optRepeat = read str }) "COUNT")
"number of times to repeat the test(s)"
- , Option ['V'] ["version"]
- (NoArg $ \opts -> opts { optShowVersion = True })
- "show version and exit"
, Option [] ["wait"]
(NoArg $ to $ \opts -> opts { optWait = True })
"wait at the end of each test"
+ , Option ['h'] ["help"]
+ (NoArg $ \opts -> opts { optShowHelp = True })
+ "show this help and exit"
+ , Option ['V'] ["version"]
+ (NoArg $ \opts -> opts { optShowVersion = True })
+ "show version and exit"
]
where
to f opts = opts { optTest = f (optTest opts) }
@@ -95,8 +101,14 @@ main = do
args <- getArgs
(opts, ofiles) <- case getOpt Permute options args of
(o, files, []) -> return (foldl (flip id) initOpts o, files)
- (_, _, errs) -> ioError (userError (concat errs ++ usageInfo header options))
- where header = "Usage: erebos-tester [OPTION...]"
+ (_, _, errs) -> do
+ hPutStrLn stderr $ concat errs <> "Try `erebos-tester --help' for more information."
+ exitFailure
+
+ when (optShowHelp opts) $ do
+ let header = "Usage: erebos-tester [OPTION...]"
+ putStrLn $ usageInfo header options
+ exitSuccess
when (optShowVersion opts) $ do
putStrLn versionLine