--batch-keys
New --batch-keys option added to these commands: get, drop, move, copy, whereis git-annex-matching-options had to be reworded since some of its options can be used to match on keys, not only files. Sponsored-by: Luke Shumaker on Patreon
This commit is contained in:
parent
c64e80b357
commit
ab7b5a492c
33 changed files with 244 additions and 133 deletions
|
@ -50,7 +50,7 @@ data AddOptions = AddOptions
|
|||
optParser :: CmdParamsDesc -> Parser AddOptions
|
||||
optParser desc = AddOptions
|
||||
<$> cmdParams desc
|
||||
<*> parseBatchOption
|
||||
<*> parseBatchOption False
|
||||
<*> switch
|
||||
( long "update"
|
||||
<> short 'u'
|
||||
|
@ -95,7 +95,7 @@ seek o = startConcurrency commandStages $ do
|
|||
Batch fmt
|
||||
| updateOnly o ->
|
||||
giveup "--update --batch is not supported"
|
||||
| otherwise -> batchFilesMatching fmt gofile
|
||||
| otherwise -> batchFiles fmt gofile
|
||||
NoBatch -> do
|
||||
-- Avoid git ls-files complaining about files that
|
||||
-- are not known to git yet, since this will add
|
||||
|
|
|
@ -76,7 +76,7 @@ optParser desc = AddUrlOptions
|
|||
<> help "add a suffix to the filename"
|
||||
))
|
||||
<*> parseDownloadOptions True
|
||||
<*> parseBatchOption
|
||||
<*> parseBatchOption False
|
||||
<*> switch
|
||||
( long "with-files"
|
||||
<> help "parse batch mode lines of the form \"$url $file\""
|
||||
|
|
|
@ -26,7 +26,7 @@ data CheckPresentKeyOptions = CheckPresentKeyOptions
|
|||
optParser :: CmdParamsDesc -> Parser CheckPresentKeyOptions
|
||||
optParser desc = CheckPresentKeyOptions
|
||||
<$> cmdParams desc
|
||||
<*> parseBatchOption
|
||||
<*> parseBatchOption False
|
||||
|
||||
seek :: CheckPresentKeyOptions -> CommandSeek
|
||||
seek o = case batchOption o of
|
||||
|
|
|
@ -33,7 +33,7 @@ optParser desc = CopyOptions
|
|||
<*> parseFromToHereOptions
|
||||
<*> optional (parseKeyOptions <|> parseFailedTransfersOption)
|
||||
<*> parseAutoOption
|
||||
<*> parseBatchOption
|
||||
<*> parseBatchOption True
|
||||
|
||||
instance DeferredParseClass CopyOptions where
|
||||
finishParse v = CopyOptions
|
||||
|
@ -48,10 +48,10 @@ seek o = startConcurrency commandStages $ do
|
|||
case batchOption o of
|
||||
NoBatch -> withKeyOptions
|
||||
(keyOptions o) (autoMode o) seeker
|
||||
(commandAction . Command.Move.startKey (fromToOptions o) Command.Move.RemoveNever)
|
||||
(commandAction . keyaction)
|
||||
(withFilesInGitAnnex ww seeker)
|
||||
=<< workTreeItems ww (copyFiles o)
|
||||
Batch fmt -> batchAnnexedFilesMatching fmt seeker
|
||||
Batch fmt -> batchAnnexed fmt seeker keyaction
|
||||
where
|
||||
ww = WarnUnmatchLsFiles
|
||||
|
||||
|
@ -63,6 +63,7 @@ seek o = startConcurrency commandStages $ do
|
|||
Left ToHere -> Just False
|
||||
, usesLocationLog = True
|
||||
}
|
||||
keyaction = Command.Move.startKey (fromToOptions o) Command.Move.RemoveNever
|
||||
|
||||
{- A copy is just a move that does not delete the source file.
|
||||
- However, auto mode avoids unnecessary copies, and avoids getting or
|
||||
|
|
|
@ -41,7 +41,7 @@ optParser desc = DropOptions
|
|||
<*> optional parseDropFromOption
|
||||
<*> parseAutoOption
|
||||
<*> optional parseKeyOptions
|
||||
<*> parseBatchOption
|
||||
<*> parseBatchOption True
|
||||
|
||||
parseDropFromOption :: Parser (DeferredParse Remote)
|
||||
parseDropFromOption = parseRemoteOption <$> strOption
|
||||
|
@ -67,11 +67,11 @@ seek o = startConcurrency commandStages $ do
|
|||
, usesLocationLog = True
|
||||
}
|
||||
case batchOption o of
|
||||
Batch fmt -> batchAnnexedFilesMatching fmt seeker
|
||||
NoBatch -> withKeyOptions (keyOptions o) (autoMode o) seeker
|
||||
(commandAction . startKeys o from)
|
||||
(withFilesInGitAnnex ww seeker)
|
||||
=<< workTreeItems ww (dropFiles o)
|
||||
Batch fmt -> batchAnnexed fmt seeker (startKeys o from)
|
||||
where
|
||||
ww = WarnUnmatchLsFiles
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ data DropKeyOptions = DropKeyOptions
|
|||
optParser :: CmdParamsDesc -> Parser DropKeyOptions
|
||||
optParser desc = DropKeyOptions
|
||||
<$> cmdParams desc
|
||||
<*> parseBatchOption
|
||||
<*> parseBatchOption False
|
||||
|
||||
seek :: DropKeyOptions -> CommandSeek
|
||||
seek o = do
|
||||
|
|
|
@ -39,7 +39,7 @@ optParser desc = FindOptions
|
|||
<$> cmdParams desc
|
||||
<*> optional parseFormatOption
|
||||
<*> optional parseBranchKeysOption
|
||||
<*> parseBatchOption
|
||||
<*> parseBatchOption False
|
||||
|
||||
parseFormatOption :: Parser Utility.Format.Format
|
||||
parseFormatOption =
|
||||
|
@ -69,7 +69,7 @@ seek o = do
|
|||
(commandAction . startKeys o)
|
||||
(withFilesInGitAnnex ww seeker)
|
||||
=<< workTreeItems ww (findThese o)
|
||||
Batch fmt -> batchAnnexedFilesMatching fmt seeker
|
||||
Batch fmt -> batchAnnexedFiles fmt seeker
|
||||
where
|
||||
ww = WarnUnmatchLsFiles
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ data FromKeyOptions = FromKeyOptions
|
|||
optParser :: CmdParamsDesc -> Parser FromKeyOptions
|
||||
optParser desc = FromKeyOptions
|
||||
<$> cmdParams desc
|
||||
<*> parseBatchOption
|
||||
<*> parseBatchOption False
|
||||
|
||||
seek :: FromKeyOptions -> CommandSeek
|
||||
seek o = do
|
||||
|
@ -43,7 +43,7 @@ seek o = do
|
|||
case (batchOption o, keyFilePairs o) of
|
||||
(Batch fmt, _) -> seekBatch matcher fmt
|
||||
-- older way of enabling batch input, does not support BatchNull
|
||||
(NoBatch, []) -> seekBatch matcher BatchLine
|
||||
(NoBatch, []) -> seekBatch matcher (BatchFormat BatchLine (BatchKeys False))
|
||||
(NoBatch, ps) -> do
|
||||
force <- Annex.getState Annex.force
|
||||
withPairs (commandAction . start matcher force) ps
|
||||
|
|
|
@ -34,7 +34,7 @@ optParser desc = GetOptions
|
|||
<*> optional (parseRemoteOption <$> parseFromOption)
|
||||
<*> parseAutoOption
|
||||
<*> optional (parseIncompleteOption <|> parseKeyOptions <|> parseFailedTransfersOption)
|
||||
<*> parseBatchOption
|
||||
<*> parseBatchOption True
|
||||
|
||||
seek :: GetOptions -> CommandSeek
|
||||
seek o = startConcurrency downloadStages $ do
|
||||
|
@ -49,7 +49,7 @@ seek o = startConcurrency downloadStages $ do
|
|||
(commandAction . startKeys from)
|
||||
(withFilesInGitAnnex ww seeker)
|
||||
=<< workTreeItems ww (getFiles o)
|
||||
Batch fmt -> batchAnnexedFilesMatching fmt seeker
|
||||
Batch fmt -> batchAnnexed fmt seeker (startKeys from)
|
||||
where
|
||||
ww = WarnUnmatchLsFiles
|
||||
|
||||
|
|
|
@ -114,7 +114,7 @@ optParser desc = InfoOptions
|
|||
( long "bytes"
|
||||
<> help "display file sizes in bytes"
|
||||
)
|
||||
<*> parseBatchOption
|
||||
<*> parseBatchOption False
|
||||
|
||||
seek :: InfoOptions -> CommandSeek
|
||||
seek o = case batchOption o of
|
||||
|
|
|
@ -44,7 +44,7 @@ optParser desc = MetaDataOptions
|
|||
<$> cmdParams desc
|
||||
<*> ((Get <$> getopt) <|> (Set <$> some modopts) <|> pure GetAll)
|
||||
<*> optional parseKeyOptions
|
||||
<*> parseBatchOption
|
||||
<*> parseBatchOption False
|
||||
where
|
||||
getopt = option (eitherReader (mkMetaField . T.pack))
|
||||
( long "get" <> short 'g' <> metavar paramField
|
||||
|
|
|
@ -44,7 +44,7 @@ optParser desc = MoveOptions
|
|||
<*> parseFromToHereOptions
|
||||
<*> pure RemoveSafe
|
||||
<*> optional (parseKeyOptions <|> parseFailedTransfersOption)
|
||||
<*> parseBatchOption
|
||||
<*> parseBatchOption True
|
||||
|
||||
instance DeferredParseClass MoveOptions where
|
||||
finishParse v = MoveOptions
|
||||
|
@ -61,10 +61,10 @@ seek :: MoveOptions -> CommandSeek
|
|||
seek o = startConcurrency stages $ do
|
||||
case batchOption o of
|
||||
NoBatch -> withKeyOptions (keyOptions o) False seeker
|
||||
(commandAction . startKey (fromToOptions o) (removeWhen o))
|
||||
(commandAction . keyaction)
|
||||
(withFilesInGitAnnex ww seeker)
|
||||
=<< workTreeItems ww (moveFiles o)
|
||||
Batch fmt -> batchAnnexedFilesMatching fmt seeker
|
||||
Batch fmt -> batchAnnexed fmt seeker keyaction
|
||||
where
|
||||
seeker = AnnexedFileSeeker
|
||||
{ startAction = start (fromToOptions o) (removeWhen o)
|
||||
|
@ -78,6 +78,7 @@ seek o = startConcurrency stages $ do
|
|||
Right (FromRemote _) -> downloadStages
|
||||
Right (ToRemote _) -> commandStages
|
||||
Left ToHere -> downloadStages
|
||||
keyaction = startKey (fromToOptions o) (removeWhen o)
|
||||
ww = WarnUnmatchLsFiles
|
||||
|
||||
start :: FromToHereOptions -> RemoveWhen -> SeekInput -> RawFilePath -> Key -> CommandStart
|
||||
|
|
|
@ -33,7 +33,7 @@ data ReKeyOptions = ReKeyOptions
|
|||
optParser :: CmdParamsDesc -> Parser ReKeyOptions
|
||||
optParser desc = ReKeyOptions
|
||||
<$> cmdParams desc
|
||||
<*> parseBatchOption
|
||||
<*> parseBatchOption False
|
||||
|
||||
-- Split on the last space, since a FilePath can contain whitespace,
|
||||
-- but a Key very rarely does.
|
||||
|
|
|
@ -28,11 +28,12 @@ data RegisterUrlOptions = RegisterUrlOptions
|
|||
optParser :: CmdParamsDesc -> Parser RegisterUrlOptions
|
||||
optParser desc = RegisterUrlOptions
|
||||
<$> cmdParams desc
|
||||
<*> parseBatchOption
|
||||
<*> parseBatchOption False
|
||||
|
||||
seek :: RegisterUrlOptions -> CommandSeek
|
||||
seek o = case (batchOption o, keyUrlPairs o) of
|
||||
(Batch fmt, _) -> commandAction $ startMass setUrlPresent fmt
|
||||
(Batch (BatchFormat sep _), _) ->
|
||||
commandAction $ startMass setUrlPresent sep
|
||||
-- older way of enabling batch input, does not support BatchNull
|
||||
(NoBatch, []) -> commandAction $ startMass setUrlPresent BatchLine
|
||||
(NoBatch, ps) -> withWords (commandAction . start setUrlPresent) ps
|
||||
|
@ -46,14 +47,15 @@ start a (keyname:url:[]) =
|
|||
si = SeekInput [keyname, url]
|
||||
start _ _ = giveup "specify a key and an url"
|
||||
|
||||
startMass :: (Key -> URLString -> Annex ()) -> BatchFormat -> CommandStart
|
||||
startMass a fmt =
|
||||
startMass :: (Key -> URLString -> Annex ()) -> BatchSeparator -> CommandStart
|
||||
startMass a sep =
|
||||
starting "registerurl" (ActionItemOther (Just "stdin")) (SeekInput []) $
|
||||
performMass a fmt
|
||||
performMass a sep
|
||||
|
||||
performMass :: (Key -> URLString -> Annex ()) -> BatchFormat -> CommandPerform
|
||||
performMass a fmt = go True =<< map (separate (== ' ')) <$> batchLines fmt
|
||||
performMass :: (Key -> URLString -> Annex ()) -> BatchSeparator -> CommandPerform
|
||||
performMass a sep = go True =<< map (separate (== ' ')) <$> batchLines fmt
|
||||
where
|
||||
fmt = BatchFormat sep (BatchKeys False)
|
||||
go status [] = next $ return status
|
||||
go status ((keyname,u):rest) | not (null keyname) && not (null u) = do
|
||||
let key = keyOpt keyname
|
||||
|
|
|
@ -25,7 +25,7 @@ data RmUrlOptions = RmUrlOptions
|
|||
optParser :: CmdParamsDesc -> Parser RmUrlOptions
|
||||
optParser desc = RmUrlOptions
|
||||
<$> cmdParams desc
|
||||
<*> parseBatchOption
|
||||
<*> parseBatchOption False
|
||||
|
||||
seek :: RmUrlOptions -> CommandSeek
|
||||
seek o = case batchOption o of
|
||||
|
|
|
@ -26,7 +26,7 @@ data SetPresentKeyOptions = SetPresentKeyOptions
|
|||
optParser :: CmdParamsDesc -> Parser SetPresentKeyOptions
|
||||
optParser desc = SetPresentKeyOptions
|
||||
<$> cmdParams desc
|
||||
<*> parseBatchOption
|
||||
<*> parseBatchOption False
|
||||
|
||||
seek :: SetPresentKeyOptions -> CommandSeek
|
||||
seek o = case batchOption o of
|
||||
|
|
|
@ -21,7 +21,7 @@ cmd = command "unregisterurl"
|
|||
|
||||
seek :: RegisterUrlOptions -> CommandSeek
|
||||
seek o = case (batchOption o, keyUrlPairs o) of
|
||||
(Batch fmt, _) -> commandAction $ startMass unregisterUrl fmt
|
||||
(Batch (BatchFormat sep _), _) -> commandAction $ startMass unregisterUrl sep
|
||||
(NoBatch, ps) -> withWords (commandAction . start unregisterUrl) ps
|
||||
|
||||
unregisterUrl :: Key -> String -> Annex ()
|
||||
|
|
|
@ -39,7 +39,7 @@ optParser :: CmdParamsDesc -> Parser WhereisOptions
|
|||
optParser desc = WhereisOptions
|
||||
<$> cmdParams desc
|
||||
<*> optional parseKeyOptions
|
||||
<*> parseBatchOption
|
||||
<*> parseBatchOption True
|
||||
<*> optional parseFormatOption
|
||||
|
||||
parseFormatOption :: Parser Utility.Format.Format
|
||||
|
@ -62,7 +62,7 @@ seek o = do
|
|||
(commandAction . startKeys o m)
|
||||
(withFilesInGitAnnex ww seeker)
|
||||
=<< workTreeItems ww (whereisFiles o)
|
||||
Batch fmt -> batchAnnexedFilesMatching fmt seeker
|
||||
Batch fmt -> batchAnnexed fmt seeker (startKeys o m)
|
||||
where
|
||||
ww = WarnUnmatchLsFiles
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue