addurl: Added --batch option.
This commit is contained in:
parent
a1927c6adb
commit
a8b398c1fa
4 changed files with 30 additions and 8 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
1
debian/changelog
vendored
1
debian/changelog
vendored
|
@ -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 <id@joeyh.name> Sat, 19 Dec 2015 13:31:17 -0400
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue