diff options
author | Joey Hess <joeyh@joeyh.name> | 2016-01-19 17:46:46 -0400 |
---|---|---|
committer | Joey Hess <joeyh@joeyh.name> | 2016-01-19 17:48:42 -0400 |
commit | 90b1891e1e2be29ae122a2613a462959f3c32611 (patch) | |
tree | 306af03e34b7d219d178a3f0d16975b8de5ca58a /CmdLine | |
parent | 8d1ac05755f970f0ec9553c9a7680a5512726c28 (diff) |
add --batch
Diffstat (limited to 'CmdLine')
-rw-r--r-- | CmdLine/Action.hs | 13 | ||||
-rw-r--r-- | CmdLine/Batch.hs | 11 |
2 files changed, 20 insertions, 4 deletions
diff --git a/CmdLine/Action.hs b/CmdLine/Action.hs index 60e108bee..693a6814f 100644 --- a/CmdLine/Action.hs +++ b/CmdLine/Action.hs @@ -134,15 +134,20 @@ includeCommandAction a = account =<< tryIO (callCommandAction a) - stages, without catching errors. Useful if one command wants to run - part of another command. -} callCommandAction :: CommandStart -> CommandCleanup -callCommandAction = start +callCommandAction = fromMaybe True <$$> callCommandAction' + +{- Like callCommandAction, but returns Nothing when the command did not + - perform any action. -} +callCommandAction' :: CommandStart -> Annex (Maybe Bool) +callCommandAction' = start where start = stage $ maybe skip perform perform = stage $ maybe failure cleanup cleanup = stage $ status stage = (=<<) - skip = return True - failure = showEndFail >> return False - status r = showEndResult r >> return r + skip = return Nothing + failure = showEndFail >> return (Just False) + status r = showEndResult r >> return (Just r) {- Do concurrent output when that has been requested. -} allowConcurrentOutput :: Annex a -> Annex a diff --git a/CmdLine/Batch.hs b/CmdLine/Batch.hs index d8d210de4..e7706881a 100644 --- a/CmdLine/Batch.hs +++ b/CmdLine/Batch.hs @@ -54,3 +54,14 @@ batchInput parser a = do batchInput parser a where parseerr s = error $ "Batch input parse failure: " ++ s + +-- Runs a CommandStart in batch mode. +-- +-- The batch mode user expects to read a line of output, and it's up to the +-- CommandStart to generate that output as it succeeds or fails to do its +-- job. However, if it stops without doing anything, it won't generate +-- any output, so in that case, batchBadInput is used to provide the caller +-- with an empty line. +batchCommandAction :: CommandStart -> Annex () +batchCommandAction a = maybe (batchBadInput Batch) (const noop) + =<< callCommandAction' a |