remove callCommandAction'
authorJoey Hess <joeyh@joeyh.name>
Wed, 16 Sep 2020 14:53:16 +0000 (10:53 -0400)
committerJoey Hess <joeyh@joeyh.name>
Wed, 16 Sep 2020 14:53:16 +0000 (10:53 -0400)
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
CmdLine/Batch.hs

index f1d9eda2982d909c15276c902a19a0db80759803..a308488876d202062f63c3fced2906e2c231e5d7 100644 (file)
@@ -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 = 
index 2e1feda8b7b1781125d96567f3ea4521321fca71..2cee7720a0e9bf348aaf4c91d7cc57c6bb98980c 100644 (file)
@@ -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.