diff options
author | Alexander Foremny <aforemny@posteo.de> | 2023-12-27 09:38:30 +0100 |
---|---|---|
committer | Alexander Foremny <aforemny@posteo.de> | 2023-12-27 09:38:30 +0100 |
commit | 2d3effac83121e3f30806eaa99f9659a2d1c71a7 (patch) | |
tree | 15f29ed1f0718c3f6160c4869680b4e6e7247937 /app | |
parent | 06495388e1b2cba724962b7268861a88e73fda8d (diff) |
chore: add `--auto` to `consume`
Diffstat (limited to 'app')
-rw-r--r-- | app/Main.hs | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/app/Main.hs b/app/Main.hs index 186b69f..0ca099b 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -2,6 +2,7 @@ {-# LANGUAGE DataKinds #-} {-# LANGUAGE DuplicateRecordFields #-} {-# LANGUAGE LambdaCase #-} +{-# LANGUAGE MultiWayIf #-} {-# LANGUAGE OverloadedRecordDot #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE QuasiQuotes #-} @@ -63,7 +64,8 @@ data Cmd inputs :: [FilePath], prompt :: Bool, force :: Bool, - language :: Maybe String + language :: Maybe String, + auto :: Bool } | Edit { indexNames :: [FilePath] @@ -117,6 +119,7 @@ consumeCmd = <*> promptArg <*> forceArg <*> languageArg + <*> autoArg editCmd :: O.Parser Cmd editCmd = @@ -185,6 +188,14 @@ forceArg = <> O.help "Force operation, overriding safety checks" ) +autoArg :: O.Parser Bool +autoArg = + O.switch + ( O.long "auto" + <> O.short 'a' + <> O.help "Automatically tag document(s)" + ) + filtersArg :: O.Parser [Filter] filtersArg = O.many $ @@ -308,7 +319,7 @@ main = do ensureDir "index" O.execParser (O.info (args O.<**> O.helper) O.idm) >>= \case - Args {cmd = Consume {keep, inputs, force, prompt, language}} -> do + Args {cmd = Consume {keep, inputs, force, prompt, language, auto}} -> do indexNames <- parMapM ( consume1 @@ -320,9 +331,10 @@ main = do docs <- mapM (readDocument . (<.> "json")) indexNames allDocs <- getDocuments docs' <- - if prompt - then processDocumentsInteractively settings allDocs docs - else processDocuments settings allDocs docs + if + | auto -> processDocuments settings allDocs docs + | prompt -> processDocumentsInteractively settings allDocs docs + | otherwise -> pure docs mapM_ ( \doc -> do printf "%s\n" (takeBaseName doc.iFileName) @@ -642,8 +654,8 @@ applyTags tags' doc = do addTags tags (removeTags untags doc) where (untags, tags) = - first (map (\tagKey -> G.Tag tagKey Nothing)) - $ partitionEithers tags' + first (map (\tagKey -> G.Tag tagKey Nothing)) $ + partitionEithers tags' addTags :: [G.Tag] -> Document -> Document addTags tags doc = |