diff --git a/CmdLine/Action.hs b/CmdLine/Action.hs index f1d9eda298..a308488876 100644 --- a/CmdLine/Action.hs +++ b/CmdLine/Action.hs @@ -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 - Just (startmsg, perform) -> do - showStartMessage startmsg - Just <$> performCommandAction' startmsg perform +callCommandAction start = start >>= \case + Just (startmsg, perform) -> do + showStartMessage startmsg + performCommandAction' startmsg perform + Nothing -> return True performCommandAction' :: StartMessage -> CommandPerform -> CommandCleanup performCommandAction' startmsg perform = diff --git a/CmdLine/Batch.hs b/CmdLine/Batch.hs index 2e1feda8b7..2cee7720a0 100644 --- a/CmdLine/Batch.hs +++ b/CmdLine/Batch.hs @@ -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.