From 47e17eec1e191e24a718a045c1550d5b5511428f Mon Sep 17 00:00:00 2001 From: Alexander Foremny Date: Fri, 22 Dec 2023 07:49:29 +0100 Subject: feat: add `--edit` to `list` --- app/Main.hs | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/app/Main.hs b/app/Main.hs index 2e64edc..1c108fe 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -58,7 +58,8 @@ data Cmd { filters :: [Filter], todo :: Bool, view :: Bool, - redo :: Bool + redo :: Bool, + edit :: Bool } | Todo | View @@ -102,6 +103,7 @@ listCmd = <*> todoArg <*> viewArg <*> redoArg + <*> editArg todoCmd :: O.Parser Cmd todoCmd = @@ -163,6 +165,13 @@ redoArg = <> O.help "Redo OCR on listed document(s)" ) +editArg :: O.Parser Bool +editArg = + O.switch + ( O.long "edit" + <> O.help "Run command `edit` on listed document(s)" + ) + viewArg :: O.Parser Bool viewArg = O.switch @@ -188,7 +197,7 @@ main = do Args {cmd = Edit {indexNames}} -> do editDocuments =<< mapM (readDocument . (<.> "json")) indexNames - Args {cmd = List {filters, redo, todo = False, view = False}} -> do + Args {cmd = List {filters, redo, todo = False, view = False, edit = False}} -> do doRedoIf filters redo mapM_ ( \(Document {iFileName, index}) -> do @@ -198,6 +207,11 @@ main = do ) . applyFilters filters =<< getDocuments + Args {cmd = List {filters, redo, edit = True}} -> do + doRedoIf filters redo + editDocuments + . applyFilters filters + =<< getDocuments Args {cmd = List {filters, redo, todo = True}} -> do doRedoIf filters redo processDocuments @@ -670,7 +684,12 @@ sh cmd = do ExitFailure exitCode' -> throwIO $ ProcessException exitCode' err sh_ :: String -> IO () -sh_ = fmap (\_ -> ()) . sh +sh_ cmd = do + -- printf "+ %s\n" cmd + (exitCode, err) <- readProcessStderr (fromString cmd) + case exitCode of + ExitSuccess -> return () + ExitFailure exitCode' -> throwIO $ ProcessException exitCode' err rightToMaybe :: Either e a -> Maybe a rightToMaybe = either (const Nothing) Just -- cgit v1.2.3