diff options
author | Joey Hess <joeyh@joeyh.name> | 2015-12-21 17:12:46 -0400 |
---|---|---|
committer | Joey Hess <joeyh@joeyh.name> | 2015-12-21 17:12:46 -0400 |
commit | 80af78f48eb59fa33849eedc5779e3649328cde0 (patch) | |
tree | 6034ff3761f206c7cea50008fb9092bc43e81283 /CmdLine | |
parent | 4263eb776a3b81354c77d2a1b3fd997ed85f1c3c (diff) | |
parent | ae0059cac6a403cbeae66483a363fe64025beb69 (diff) |
Merge branch 'master' into smudge
Diffstat (limited to 'CmdLine')
-rw-r--r-- | CmdLine/Batch.hs | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/CmdLine/Batch.hs b/CmdLine/Batch.hs index 57823b67b..ce9127975 100644 --- a/CmdLine/Batch.hs +++ b/CmdLine/Batch.hs @@ -12,15 +12,13 @@ import Command data BatchMode = Batch | NoBatch -batchOption :: Parser BatchMode -batchOption = flag NoBatch Batch +parseBatchOption :: Parser BatchMode +parseBatchOption = flag NoBatch Batch ( long "batch" <> help "enable batch mode" ) -type Batchable t = BatchMode -> t -> CommandStart - --- A Batchable command can run in batch mode, or not. +-- A batchable command can run in batch mode, or not. -- In batch mode, one line at a time is read, parsed, and a reply output to -- stdout. In non batch mode, the command's parameters are parsed and -- a reply output for each. @@ -29,7 +27,7 @@ batchable handler parser paramdesc = batchseeker <$> batchparser where batchparser = (,,) <$> parser - <*> batchOption + <*> parseBatchOption <*> cmdParams paramdesc batchseeker (opts, NoBatch, params) = mapM_ (go NoBatch opts) params @@ -52,3 +50,13 @@ batchable handler parser paramdesc = batchseeker <$> batchparser batchBadInput :: BatchMode -> Annex () batchBadInput NoBatch = liftIO exitFailure batchBadInput Batch = liftIO $ putStrLn "" + +-- Reads lines of batch mode input and passes to the action to handle. +batchSeek :: (String -> Annex ()) -> Annex () +batchSeek a = do + mp <- liftIO $ catchMaybeIO getLine + case mp of + Nothing -> return () + Just p -> do + a p + batchSeek a |