Merge branch 'master' into smudge
This commit is contained in:
commit
d82b110da8
35 changed files with 463 additions and 71 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue