summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoman Smrž <roman.smrz@seznam.cz>2024-05-29 20:43:05 +0200
committerRoman Smrž <roman.smrz@seznam.cz>2024-05-29 20:47:29 +0200
commit7aa84dc168556f65b09d2b0b0281bc9404155145 (patch)
tree32e611d1a821ffa198f6640d8cc69e4fa795e1c9
parentd0ed55916824f222d53eb6c038ef8dea2c0892b7 (diff)
Show usage info only with explicit `--help' option
-rw-r--r--src/Main.hs21
1 files changed, 16 insertions, 5 deletions
diff --git a/src/Main.hs b/src/Main.hs
index 318c36f..363fad8 100644
--- a/src/Main.hs
+++ b/src/Main.hs
@@ -20,17 +20,22 @@ import Job
import Version
data CmdlineOptions = CmdlineOptions
- { optShowVersion :: Bool
+ { optShowHelp :: Bool
+ , optShowVersion :: Bool
}
defaultCmdlineOptions :: CmdlineOptions
defaultCmdlineOptions = CmdlineOptions
- { optShowVersion = False
+ { optShowHelp = False
+ , optShowVersion = False
}
options :: [OptDescr (CmdlineOptions -> CmdlineOptions)]
options =
- [ Option ['V'] ["version"]
+ [ 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"
]
@@ -81,8 +86,14 @@ main = do
args <- getArgs
opts <- case getOpt Permute options args of
(o, _, []) -> return (foldl (flip id) defaultCmdlineOptions o)
- (_, _, errs) -> ioError (userError (concat errs ++ usageInfo header options))
- where header = "Usage: minici [OPTION...]"
+ (_, _, errs) -> do
+ hPutStrLn stderr $ concat errs <> "Try `minici --help' for more information."
+ exitFailure
+
+ when (optShowHelp opts) $ do
+ let header = "Usage: minici [<option>...]"
+ putStr $ usageInfo header options
+ exitSuccess
when (optShowVersion opts) $ do
putStrLn versionLine