diff options
author | Joey Hess <joeyh@joeyh.name> | 2015-12-22 18:10:40 -0400 |
---|---|---|
committer | Joey Hess <joeyh@joeyh.name> | 2015-12-22 18:10:40 -0400 |
commit | 52bce14ce4f6c4e7600c22819f655b9762f09e19 (patch) | |
tree | c3c2bf691767ef56d83a9a493c34bd21b9bcfccf /CmdLine | |
parent | 0ee6ad2199575501c783e85b228f73a193e6672b (diff) | |
parent | 0c3a6a71c42b37d2cad29e2b259fcd192dfc39f0 (diff) |
Merge branch 'master' into smudge
Diffstat (limited to 'CmdLine')
-rw-r--r-- | CmdLine/Batch.hs | 22 |
1 files changed, 8 insertions, 14 deletions
diff --git a/CmdLine/Batch.hs b/CmdLine/Batch.hs index ce9127975..d8d210de4 100644 --- a/CmdLine/Batch.hs +++ b/CmdLine/Batch.hs @@ -31,15 +31,7 @@ batchable handler parser paramdesc = batchseeker <$> batchparser <*> cmdParams paramdesc batchseeker (opts, NoBatch, params) = mapM_ (go NoBatch opts) params - batchseeker (opts, Batch, _) = batchloop opts - - batchloop opts = do - mp <- liftIO $ catchMaybeIO getLine - case mp of - Nothing -> return () - Just p -> do - go Batch opts p - batchloop opts + batchseeker (opts, Batch, _) = batchInput Right (go Batch opts) go batchmode opts p = unlessM (handler opts p) $ @@ -52,11 +44,13 @@ 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 +batchInput :: (String -> Either String a) -> (a -> Annex ()) -> Annex () +batchInput parser a = do mp <- liftIO $ catchMaybeIO getLine case mp of Nothing -> return () - Just p -> do - a p - batchSeek a + Just v -> do + either parseerr a (parser v) + batchInput parser a + where + parseerr s = error $ "Batch input parse failure: " ++ s |