From 98194e4c61466ec9175e65af557b6130be81617d Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 21 Dec 2015 12:57:13 -0400 Subject: addurl: Added --batch option. --- CmdLine/Batch.hs | 20 ++++++++++++++------ Command/AddUrl.hs | 12 ++++++++++-- debian/changelog | 1 + doc/git-annex-addurl.mdwn | 5 +++++ 4 files changed, 30 insertions(+), 8 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 diff --git a/Command/AddUrl.hs b/Command/AddUrl.hs index af2e04a62..de83d8c9b 100644 --- a/Command/AddUrl.hs +++ b/Command/AddUrl.hs @@ -32,6 +32,7 @@ import Annex.Content.Direct import Annex.FileMatcher import Logs.Location import Utility.Metered +import CmdLine.Batch import qualified Annex.Transfer as Transfer #ifdef WITH_QUVI import Annex.Quvi @@ -51,6 +52,7 @@ data AddUrlOptions = AddUrlOptions , suffixOption :: Maybe String , relaxedOption :: Bool , rawOption :: Bool + , batchOption :: BatchMode } optParser :: CmdParamsDesc -> Parser AddUrlOptions @@ -74,6 +76,7 @@ optParser desc = AddUrlOptions )) <*> parseRelaxedOption <*> parseRawOption + <*> parseBatchOption parseRelaxedOption :: Parser Bool parseRelaxedOption = switch @@ -88,8 +91,13 @@ parseRawOption = switch ) seek :: AddUrlOptions -> CommandSeek -seek o = allowConcurrentOutput $ - forM_ (addUrls o) $ \u -> do +seek o = allowConcurrentOutput $ do + forM_ (addUrls o) go + case batchOption o of + Batch -> batchSeek go + NoBatch -> noop + where + go u = do r <- Remote.claimingUrl u if Remote.uuid r == webUUID || rawOption o then void $ commandAction $ startWeb o u diff --git a/debian/changelog b/debian/changelog index 99837e864..34e106d39 100644 --- a/debian/changelog +++ b/debian/changelog @@ -4,6 +4,7 @@ git-annex (5.20151219) UNRELEASED; urgency=medium that were present. Probably caused by a change to what git status displays in this situation. Fixed by treating files git thinks are modified the same as typechanged files. + * addurl: Added --batch option. -- Joey Hess Sat, 19 Dec 2015 13:31:17 -0400 diff --git a/doc/git-annex-addurl.mdwn b/doc/git-annex-addurl.mdwn index 0f5a763bc..eecc2c2bd 100644 --- a/doc/git-annex-addurl.mdwn +++ b/doc/git-annex-addurl.mdwn @@ -70,6 +70,11 @@ be used to get better filenames. Enables parallel downloads when multiple urls are being added. For example: `-J4` +* `--batch` + + Enables batch mode, in which lines containing urls to add are read from + stdin. + # SEE ALSO [[git-annex]](1) -- cgit v1.2.3