diff options
author | Roman Smrž <roman.smrz@seznam.cz> | 2023-04-25 22:17:58 +0200 |
---|---|---|
committer | Roman Smrž <roman.smrz@seznam.cz> | 2023-04-25 22:17:58 +0200 |
commit | 780fc8894379f28af0f03bc27c3a41aca8c95b5a (patch) | |
tree | e5bdc1db78df4a58c27a73b8fea675eb5c9328a4 /src/Main.hs | |
parent | 649ba09db13caea5de5d179c538b8a2945a9a69d (diff) |
Command-line option to report version
Diffstat (limited to 'src/Main.hs')
-rw-r--r-- | src/Main.hs | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/Main.hs b/src/Main.hs index 4e99c5f..dc30d32 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -9,11 +9,31 @@ import Data.Text (Text) import Data.Text qualified as T import Data.Text.IO qualified as T +import System.Console.GetOpt +import System.Environment +import System.Exit import System.IO import System.Process import Config import Job +import Version + +data CmdlineOptions = CmdlineOptions + { optShowVersion :: Bool + } + +defaultCmdlineOptions :: CmdlineOptions +defaultCmdlineOptions = CmdlineOptions + { optShowVersion = False + } + +options :: [OptDescr (CmdlineOptions -> CmdlineOptions)] +options = + [ Option ['V'] ["version"] + (NoArg $ \opts -> opts { optShowVersion = True }) + "show version and exit" + ] fitToLength :: Int -> Text -> Text fitToLength maxlen str | len <= maxlen = str <> T.replicate (maxlen - len) " " @@ -58,6 +78,16 @@ displayStatusLine prefix1 prefix2 statuses = do main :: IO () 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...]" + + when (optShowVersion opts) $ do + putStrLn versionLine + exitSuccess + Just configPath <- findConfig config <- parseConfig configPath |