diff options
-rw-r--r-- | CmdLine/Batch.hs | 14 | ||||
-rw-r--r-- | Command/AddUrl.hs | 26 | ||||
-rw-r--r-- | debian/changelog | 2 | ||||
-rw-r--r-- | doc/git-annex-addurl.mdwn | 8 |
4 files changed, 37 insertions, 13 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 diff --git a/Command/AddUrl.hs b/Command/AddUrl.hs index 0af7344ed..2989c5830 100644 --- a/Command/AddUrl.hs +++ b/Command/AddUrl.hs @@ -53,6 +53,7 @@ data AddUrlOptions = AddUrlOptions , relaxedOption :: Bool , rawOption :: Bool , batchOption :: BatchMode + , batchFilesOption :: Bool } optParser :: CmdParamsDesc -> Parser AddUrlOptions @@ -77,6 +78,10 @@ optParser desc = AddUrlOptions <*> parseRelaxedOption <*> parseRawOption <*> parseBatchOption + <*> switch + ( long "with-files" + <> help "parse batch mode lines of the form \"$url $file\"" + ) parseRelaxedOption :: Parser Bool parseRelaxedOption = switch @@ -92,16 +97,25 @@ parseRawOption = switch seek :: AddUrlOptions -> CommandSeek seek o = allowConcurrentOutput $ do - forM_ (addUrls o) go + forM_ (addUrls o) (\u -> go (o, u)) case batchOption o of - Batch -> batchInput go + Batch -> batchInput (parseBatchInput o) go NoBatch -> noop where - go u = do + go (o', u) = do r <- Remote.claimingUrl u - if Remote.uuid r == webUUID || rawOption o - then void $ commandAction $ startWeb o u - else checkUrl r o u + if Remote.uuid r == webUUID || rawOption o' + then void $ commandAction $ startWeb o' u + else checkUrl r o' u + +parseBatchInput :: AddUrlOptions -> String -> Either String (AddUrlOptions, URLString) +parseBatchInput o s + | batchFilesOption o = + let (u, f) = separate (== ' ') s + in if null u || null f + then Left ("parsed empty url or filename in input: " ++ s) + else Right (o { fileOption = Just f }, u) + | otherwise = Right (o, s) checkUrl :: Remote -> AddUrlOptions -> URLString -> Annex () checkUrl r o u = do diff --git a/debian/changelog b/debian/changelog index 34e106d39..73035a683 100644 --- a/debian/changelog +++ b/debian/changelog @@ -4,7 +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. + * addurl: Added --batch and --with-files options. -- Joey Hess <id@joeyh.name> Sat, 19 Dec 2015 13:31:17 -0400 diff --git a/doc/git-annex-addurl.mdwn b/doc/git-annex-addurl.mdwn index eecc2c2bd..20cec9259 100644 --- a/doc/git-annex-addurl.mdwn +++ b/doc/git-annex-addurl.mdwn @@ -75,6 +75,14 @@ be used to get better filenames. Enables batch mode, in which lines containing urls to add are read from stdin. +* `--with-files` + + When batch mode is enabled, makes it parse lines of the form: "$url $file" + + That adds the specified url to the specified file, downloading its + content if the file does not yet exist; the same as + `git annex addurl $url --file $file` + # SEE ALSO [[git-annex]](1) |