From 7aa84dc168556f65b09d2b0b0281bc9404155145 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Wed, 29 May 2024 20:43:05 +0200 Subject: Show usage info only with explicit `--help' option --- src/Main.hs | 21 ++++++++++++++++----- 1 file 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 [