summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorLibravatar Alexander Foremny <aforemny@posteo.de>2023-12-22 06:36:53 +0100
committerLibravatar Alexander Foremny <aforemny@posteo.de>2023-12-22 06:36:53 +0100
commit0b4c2d4fd9e060c8d0a307ca093b2b1b9ca7a865 (patch)
tree7613898c56806238bf975cf276b48f222be25cb3 /app
parentee67922575359b1e9e5480312fac634446fe5bd5 (diff)
feat: add `--todo` to `list`
Diffstat (limited to 'app')
-rw-r--r--app/Main.hs41
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"]