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
|
data BatchMode = Batch | NoBatch
|
||||||
|
|
||||||
batchOption :: Parser BatchMode
|
parseBatchOption :: Parser BatchMode
|
||||||
batchOption = flag NoBatch Batch
|
parseBatchOption = flag NoBatch Batch
|
||||||
( long "batch"
|
( long "batch"
|
||||||
<> help "enable batch mode"
|
<> 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
|
-- 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
|
-- stdout. In non batch mode, the command's parameters are parsed and
|
||||||
-- a reply output for each.
|
-- a reply output for each.
|
||||||
|
@ -29,7 +27,7 @@ batchable handler parser paramdesc = batchseeker <$> batchparser
|
||||||
where
|
where
|
||||||
batchparser = (,,)
|
batchparser = (,,)
|
||||||
<$> parser
|
<$> parser
|
||||||
<*> batchOption
|
<*> parseBatchOption
|
||||||
<*> cmdParams paramdesc
|
<*> cmdParams paramdesc
|
||||||
|
|
||||||
batchseeker (opts, NoBatch, params) = mapM_ (go NoBatch opts) params
|
batchseeker (opts, NoBatch, params) = mapM_ (go NoBatch opts) params
|
||||||
|
@ -52,3 +50,13 @@ batchable handler parser paramdesc = batchseeker <$> batchparser
|
||||||
batchBadInput :: BatchMode -> Annex ()
|
batchBadInput :: BatchMode -> Annex ()
|
||||||
batchBadInput NoBatch = liftIO exitFailure
|
batchBadInput NoBatch = liftIO exitFailure
|
||||||
batchBadInput Batch = liftIO $ putStrLn ""
|
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 Annex.FileMatcher
|
||||||
import Logs.Location
|
import Logs.Location
|
||||||
import Utility.Metered
|
import Utility.Metered
|
||||||
|
import CmdLine.Batch
|
||||||
import qualified Annex.Transfer as Transfer
|
import qualified Annex.Transfer as Transfer
|
||||||
#ifdef WITH_QUVI
|
#ifdef WITH_QUVI
|
||||||
import Annex.Quvi
|
import Annex.Quvi
|
||||||
|
@ -51,6 +52,7 @@ data AddUrlOptions = AddUrlOptions
|
||||||
, suffixOption :: Maybe String
|
, suffixOption :: Maybe String
|
||||||
, relaxedOption :: Bool
|
, relaxedOption :: Bool
|
||||||
, rawOption :: Bool
|
, rawOption :: Bool
|
||||||
|
, batchOption :: BatchMode
|
||||||
}
|
}
|
||||||
|
|
||||||
optParser :: CmdParamsDesc -> Parser AddUrlOptions
|
optParser :: CmdParamsDesc -> Parser AddUrlOptions
|
||||||
|
@ -74,6 +76,7 @@ optParser desc = AddUrlOptions
|
||||||
))
|
))
|
||||||
<*> parseRelaxedOption
|
<*> parseRelaxedOption
|
||||||
<*> parseRawOption
|
<*> parseRawOption
|
||||||
|
<*> parseBatchOption
|
||||||
|
|
||||||
parseRelaxedOption :: Parser Bool
|
parseRelaxedOption :: Parser Bool
|
||||||
parseRelaxedOption = switch
|
parseRelaxedOption = switch
|
||||||
|
@ -88,8 +91,13 @@ parseRawOption = switch
|
||||||
)
|
)
|
||||||
|
|
||||||
seek :: AddUrlOptions -> CommandSeek
|
seek :: AddUrlOptions -> CommandSeek
|
||||||
seek o = allowConcurrentOutput $
|
seek o = allowConcurrentOutput $ do
|
||||||
forM_ (addUrls o) $ \u -> do
|
forM_ (addUrls o) go
|
||||||
|
case batchOption o of
|
||||||
|
Batch -> batchSeek go
|
||||||
|
NoBatch -> noop
|
||||||
|
where
|
||||||
|
go u = do
|
||||||
r <- Remote.claimingUrl u
|
r <- Remote.claimingUrl u
|
||||||
if Remote.uuid r == webUUID || rawOption o
|
if Remote.uuid r == webUUID || rawOption o
|
||||||
then void $ commandAction $ startWeb o u
|
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
|
that were present. Probably caused by a change to what git status
|
||||||
displays in this situation. Fixed by treating files git thinks are
|
displays in this situation. Fixed by treating files git thinks are
|
||||||
modified the same as typechanged files.
|
modified the same as typechanged files.
|
||||||
|
* addurl: Added --batch option.
|
||||||
|
|
||||||
-- Joey Hess <id@joeyh.name> Sat, 19 Dec 2015 13:31:17 -0400
|
-- 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.
|
Enables parallel downloads when multiple urls are being added.
|
||||||
For example: `-J4`
|
For example: `-J4`
|
||||||
|
|
||||||
|
* `--batch`
|
||||||
|
|
||||||
|
Enables batch mode, in which lines containing urls to add are read from
|
||||||
|
stdin.
|
||||||
|
|
||||||
# SEE ALSO
|
# SEE ALSO
|
||||||
|
|
||||||
[[git-annex]](1)
|
[[git-annex]](1)
|
||||||
|
|
Loading…
Reference in a new issue