remove callCommandAction'
This is prep for making batchCommandAction use commandAction, which will enable concurrency for batch mode. Since commandAction can't return anything, have to handle the case of a CommandStart that chooses to do nothing in a different way.
This commit is contained in:
parent
7b4c7a7ffc
commit
7a4f3ff345
2 changed files with 15 additions and 18 deletions
|
@ -174,17 +174,11 @@ accountCommandAction startmsg cleanup = tryNonAsync cleanup >>= \case
|
||||||
- stages, without catching errors and without incrementing error counter.
|
- stages, without catching errors and without incrementing error counter.
|
||||||
- Useful if one command wants to run part of another command. -}
|
- Useful if one command wants to run part of another command. -}
|
||||||
callCommandAction :: CommandStart -> CommandCleanup
|
callCommandAction :: CommandStart -> CommandCleanup
|
||||||
callCommandAction = fromMaybe True <$$> callCommandAction'
|
callCommandAction start = start >>= \case
|
||||||
|
Just (startmsg, perform) -> do
|
||||||
{- Like callCommandAction, but returns Nothing when the command did not
|
showStartMessage startmsg
|
||||||
- perform any action. -}
|
performCommandAction' startmsg perform
|
||||||
callCommandAction' :: CommandStart -> Annex (Maybe Bool)
|
Nothing -> return True
|
||||||
callCommandAction' start =
|
|
||||||
start >>= \case
|
|
||||||
Nothing -> return Nothing
|
|
||||||
Just (startmsg, perform) -> do
|
|
||||||
showStartMessage startmsg
|
|
||||||
Just <$> performCommandAction' startmsg perform
|
|
||||||
|
|
||||||
performCommandAction' :: StartMessage -> CommandPerform -> CommandCleanup
|
performCommandAction' :: StartMessage -> CommandPerform -> CommandCleanup
|
||||||
performCommandAction' startmsg perform =
|
performCommandAction' startmsg perform =
|
||||||
|
|
|
@ -92,16 +92,19 @@ batchLines fmt = do
|
||||||
BatchLine -> lines
|
BatchLine -> lines
|
||||||
BatchNull -> splitc '\0'
|
BatchNull -> splitc '\0'
|
||||||
|
|
||||||
-- Runs a CommandStart in batch mode.
|
batchCommandAction :: CommandStart -> Annex ()
|
||||||
--
|
batchCommandAction = void . callCommandAction . batchCommandStart
|
||||||
|
|
||||||
-- The batch mode user expects to read a line of output, and it's up to the
|
-- 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
|
-- 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
|
-- 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
|
-- any output. This modifies it so in that case, an empty line is printed.
|
||||||
-- with an empty line.
|
batchCommandStart :: CommandStart -> CommandStart
|
||||||
batchCommandAction :: CommandStart -> Annex ()
|
batchCommandStart a = a >>= \case
|
||||||
batchCommandAction a = maybe (batchBadInput (Batch BatchLine)) (const noop)
|
Just v -> return (Just v)
|
||||||
=<< callCommandAction' a
|
Nothing -> do
|
||||||
|
batchBadInput (Batch BatchLine)
|
||||||
|
return Nothing
|
||||||
|
|
||||||
-- Reads lines of batch input and passes the filepaths to a CommandStart
|
-- Reads lines of batch input and passes the filepaths to a CommandStart
|
||||||
-- to handle them.
|
-- to handle them.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue