diff options
-rw-r--r-- | app/Main.hs | 41 |
1 files changed, 29 insertions, 12 deletions
diff --git a/app/Main.hs b/app/Main.hs index 32f4037..e9189d4 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -19,7 +19,6 @@ import Data.Attoparsec.Text qualified as A import Data.ByteString.Lazy qualified as LB import Data.Default import Data.Digest.Pure.SHA (sha256, showDigest) -import Data.Function ((&)) import Data.List import Data.Map qualified as M import Data.Maybe (catMaybes, fromMaybe) @@ -48,8 +47,14 @@ data Args = Args } data Cmd - = Consume Bool [FilePath] - | List [Filter] + = Consume + { keep :: Bool, + inputs :: [FilePath] + } + | List + { filters :: [Filter], + todo :: Bool + } | Todo args :: O.Parser Args @@ -71,19 +76,20 @@ consumeCmd :: O.Parser Cmd consumeCmd = Consume <$> keepArg - <*> filePathsArg + <*> inputsArg listCmd :: O.Parser Cmd listCmd = List - <$> filterArg + <$> filtersArg + <*> todoArg todoCmd :: O.Parser Cmd todoCmd = pure Todo -filePathsArg :: O.Parser [FilePath] -filePathsArg = +inputsArg :: O.Parser [FilePath] +inputsArg = O.many (O.strArgument (O.metavar "FILE" <> O.action "file")) keepArg :: O.Parser Bool @@ -93,8 +99,8 @@ keepArg = <> O.help "Keep input document" ) -filterArg :: O.Parser [Filter] -filterArg = +filtersArg :: O.Parser [Filter] +filtersArg = O.many $ O.option (O.maybeReader parse) @@ -106,6 +112,13 @@ filterArg = parse ('@' : tagKey) = Just (FilterByTag (T.pack tagKey)) parse _ = Nothing +todoArg :: O.Parser Bool +todoArg = + O.switch + ( O.long "todo" + <> O.help "Run command `todo` on listed documents." + ) + data Filter = FilterByTag T.Text @@ -118,10 +131,10 @@ main = do ensureDir "index" O.execParser (O.info (args O.<**> O.helper) O.idm) >>= \case - Args {cmd = Consume keep filePaths} -> + Args {cmd = Consume {keep, inputs}} -> mapM_ putStrLn - =<< parMapM (consume1 keep) (map (cwd </>) filePaths) - Args {cmd = List filters} -> do + =<< parMapM (consume1 keep) (map (cwd </>) inputs) + Args {cmd = List {filters, todo = False}} -> do mapM_ ( \(Document {iFileName, index}) -> do if hasTag (Tag "todo" Nothing) index @@ -130,6 +143,10 @@ main = do ) . applyFilters filters =<< getDocuments + Args {cmd = List {filters, todo = True}} -> do + processDocuments + . applyFilters filters + =<< getDocuments Args {cmd = Todo} -> do processDocuments . applyFilters [FilterByTag "todo"] |