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.
|
||||
- Useful if one command wants to run part of another command. -}
|
||||
callCommandAction :: CommandStart -> CommandCleanup
|
||||
callCommandAction = fromMaybe True <$$> callCommandAction'
|
||||
|
||||
{- Like callCommandAction, but returns Nothing when the command did not
|
||||
- perform any action. -}
|
||||
callCommandAction' :: CommandStart -> Annex (Maybe Bool)
|
||||
callCommandAction' start =
|
||||
start >>= \case
|
||||
Nothing -> return Nothing
|
||||
callCommandAction start = start >>= \case
|
||||
Just (startmsg, perform) -> do
|
||||
showStartMessage startmsg
|
||||
Just <$> performCommandAction' startmsg perform
|
||||
performCommandAction' startmsg perform
|
||||
Nothing -> return True
|
||||
|
||||
performCommandAction' :: StartMessage -> CommandPerform -> CommandCleanup
|
||||
performCommandAction' startmsg perform =
|
||||
|
|
|
@ -92,16 +92,19 @@ batchLines fmt = do
|
|||
BatchLine -> lines
|
||||
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
|
||||
-- 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 BatchLine)) (const noop)
|
||||
=<< callCommandAction' a
|
||||
-- any output. This modifies it so in that case, an empty line is printed.
|
||||
batchCommandStart :: CommandStart -> CommandStart
|
||||
batchCommandStart a = a >>= \case
|
||||
Just v -> return (Just v)
|
||||
Nothing -> do
|
||||
batchBadInput (Batch BatchLine)
|
||||
return Nothing
|
||||
|
||||
-- Reads lines of batch input and passes the filepaths to a CommandStart
|
||||
-- to handle them.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue