diff options
author | Alexander Foremny <aforemny@posteo.de> | 2023-10-16 13:02:23 +0200 |
---|---|---|
committer | Alexander Foremny <aforemny@posteo.de> | 2023-10-16 13:53:56 +0200 |
commit | 162577ddab4b440f97509f3076c6cd8ff2371059 (patch) | |
tree | d1840a75812426b2b6e3a89dbb57d40957676a08 /app | |
parent | 5981448f0de68dc1938195f4fe688128e5edbf19 (diff) |
make `internalTags` a global option
Diffstat (limited to 'app')
-rw-r--r-- | app/Main.hs | 36 |
1 files changed, 23 insertions, 13 deletions
diff --git a/app/Main.hs b/app/Main.hs index 1bb5c70..961fb99 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -346,11 +346,29 @@ import Text.Printf import TreeGrepper.Match qualified as G import Prelude hiding (id) +data Options = Options + { internalTags :: Bool, + command :: Command + } + deriving (Show) + +options :: O.Parser Options +options = + Options + <$> internalTagsFlag + <*> cmd + +internalTagsFlag :: O.Parser Bool +internalTagsFlag = + O.switch + ( O.long "internal-tags" + <> O.help "Whether to display internal tags." + ) + data Command = List { files :: [String], - filters :: [Filter], - internalTags :: Bool + filters :: [Filter] } | Show { id :: String, @@ -372,7 +390,6 @@ listCmd = List <$> filesArg <*> I.filterArg - <*> internalTagsFlag showCmd :: O.Parser Command showCmd = @@ -383,13 +400,6 @@ showCmd = filesArg :: O.Parser [String] filesArg = O.many (O.strArgument (O.metavar "FILE" <> O.action "file")) -internalTagsFlag :: O.Parser Bool -internalTagsFlag = - O.switch - ( O.long "internal-tags" - <> O.help "Whether to display internal tags." - ) - idArg :: O.Parser String idArg = O.strArgument @@ -419,8 +429,8 @@ die s = do main :: IO () main = do - O.execParser (O.info (cmd <**> O.helper) O.idm) >>= \case - List {filters, files, internalTags} -> do + O.execParser (O.info (options <**> O.helper) O.idm) >>= \case + Options {internalTags, command = List {filters, files}} -> do issues <- listIssues filters files putDoc . P.vsep $ map @@ -440,7 +450,7 @@ main = do ) ) issues - Show {id, width} -> do + Options {command = Show {id, width}} -> do issues <- listIssues [] [] case find ((==) (Just id) . I.id) issues of Nothing -> die (printf "no issue with id `%s'\n" id) |