diff options
Diffstat (limited to 'CmdLine/Batch.hs')
-rw-r--r-- | CmdLine/Batch.hs | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/CmdLine/Batch.hs b/CmdLine/Batch.hs index f07f79b04..d8d210de4 100644 --- a/CmdLine/Batch.hs +++ b/CmdLine/Batch.hs @@ -31,7 +31,7 @@ batchable handler parser paramdesc = batchseeker <$> batchparser <*> cmdParams paramdesc batchseeker (opts, NoBatch, params) = mapM_ (go NoBatch opts) params - batchseeker (opts, Batch, _) = batchInput (go Batch opts) + batchseeker (opts, Batch, _) = batchInput Right (go Batch opts) go batchmode opts p = unlessM (handler opts p) $ @@ -44,11 +44,13 @@ batchBadInput NoBatch = liftIO exitFailure batchBadInput Batch = liftIO $ putStrLn "" -- Reads lines of batch mode input and passes to the action to handle. -batchInput :: (String -> Annex ()) -> Annex () -batchInput 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 - batchInput a + Just v -> do + either parseerr a (parser v) + batchInput parser a + where + parseerr s = error $ "Batch input parse failure: " ++ s |