From 7a4f3ff3458d300207799abab584d602e3478ef0 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Wed, 16 Sep 2020 10:53:16 -0400 Subject: [PATCH] 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. --- CmdLine/Action.hs | 16 +++++----------- CmdLine/Batch.hs | 17 ++++++++++------- 2 files changed, 15 insertions(+), 18 deletions(-) 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.