diff options
Diffstat (limited to 'app/Main.hs')
-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) |