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 /Command/AddUrl.hs | |
parent | 0ee6ad2199575501c783e85b228f73a193e6672b (diff) | |
parent | 0c3a6a71c42b37d2cad29e2b259fcd192dfc39f0 (diff) |
Merge branch 'master' into smudge
Diffstat (limited to 'Command/AddUrl.hs')
-rw-r--r-- | Command/AddUrl.hs | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/Command/AddUrl.hs b/Command/AddUrl.hs index 659274e49..746a6725c 100644 --- a/Command/AddUrl.hs +++ b/Command/AddUrl.hs @@ -54,6 +54,7 @@ data AddUrlOptions = AddUrlOptions , relaxedOption :: Bool , rawOption :: Bool , batchOption :: BatchMode + , batchFilesOption :: Bool } optParser :: CmdParamsDesc -> Parser AddUrlOptions @@ -78,6 +79,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 @@ -93,16 +98,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 -> batchSeek 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 |