addurl: Added --with-files option.

This commit is contained in:
Joey Hess 2015-12-22 12:20:39 -04:00
parent 03f2ae0423
commit 2dce8081a6
Failed to extract signature
4 changed files with 37 additions and 13 deletions

View file

@ -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

View file

@ -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

2
debian/changelog vendored
View file

@ -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

View file

@ -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)