setpresentkey: Added --batch support (for ronnypfa)
This commit was sponsored by Peter on Patreon.
This commit is contained in:
parent
940444994e
commit
c3064edac9
3 changed files with 39 additions and 10 deletions
|
@ -24,6 +24,7 @@ git-annex (6.20180510) UNRELEASED; urgency=medium
|
||||||
* git-annex-shell: GIT_ANNEX_SHELL_APPENDONLY makes it allow writes,
|
* git-annex-shell: GIT_ANNEX_SHELL_APPENDONLY makes it allow writes,
|
||||||
but not deletion of annexed content. Note that securing pushes to
|
but not deletion of annexed content. Note that securing pushes to
|
||||||
the git repository is left up to the user.
|
the git repository is left up to the user.
|
||||||
|
* setpresentkey: Added --batch support.
|
||||||
|
|
||||||
-- Joey Hess <id@joeyh.name> Mon, 14 May 2018 13:42:41 -0400
|
-- Joey Hess <id@joeyh.name> Mon, 14 May 2018 13:42:41 -0400
|
||||||
|
|
||||||
|
|
|
@ -16,19 +16,40 @@ cmd = noCommit $
|
||||||
command "setpresentkey" SectionPlumbing
|
command "setpresentkey" SectionPlumbing
|
||||||
"change records of where key is present"
|
"change records of where key is present"
|
||||||
(paramPair paramKey (paramPair paramUUID "[1|0]"))
|
(paramPair paramKey (paramPair paramUUID "[1|0]"))
|
||||||
(withParams seek)
|
(seek <$$> optParser)
|
||||||
|
|
||||||
seek :: CmdParams -> CommandSeek
|
data SetPresentKeyOptions = SetPresentKeyOptions
|
||||||
seek = withWords start
|
{ params :: CmdParams
|
||||||
|
, batchOption :: BatchMode
|
||||||
|
}
|
||||||
|
|
||||||
start :: [String] -> CommandStart
|
optParser :: CmdParamsDesc -> Parser SetPresentKeyOptions
|
||||||
start (ks:us:vs:[]) = do
|
optParser desc = SetPresentKeyOptions
|
||||||
|
<$> cmdParams desc
|
||||||
|
<*> parseBatchOption
|
||||||
|
|
||||||
|
seek :: SetPresentKeyOptions -> CommandSeek
|
||||||
|
seek o = case batchOption o of
|
||||||
|
Batch -> batchInput
|
||||||
|
(parseKeyStatus . words)
|
||||||
|
(batchCommandAction . start)
|
||||||
|
NoBatch -> either giveup (commandAction . start)
|
||||||
|
(parseKeyStatus $ params o)
|
||||||
|
|
||||||
|
data KeyStatus = KeyStatus Key UUID LogStatus
|
||||||
|
|
||||||
|
parseKeyStatus :: [String] -> Either String KeyStatus
|
||||||
|
parseKeyStatus (ks:us:vs:[]) = do
|
||||||
|
k <- maybe (Left "bad key") Right (file2key ks)
|
||||||
|
let u = toUUID us
|
||||||
|
s <- maybe (Left "bad value") Right (parseStatus vs)
|
||||||
|
return $ KeyStatus k u s
|
||||||
|
parseKeyStatus _ = Left "Bad input. Expected: key uuid value"
|
||||||
|
|
||||||
|
start :: KeyStatus -> CommandStart
|
||||||
|
start (KeyStatus k u s) = do
|
||||||
showStartKey "setpresentkey" k (mkActionItem k)
|
showStartKey "setpresentkey" k (mkActionItem k)
|
||||||
next $ perform k (toUUID us) s
|
next $ perform k u s
|
||||||
where
|
|
||||||
k = fromMaybe (giveup "bad key") (file2key ks)
|
|
||||||
s = fromMaybe (giveup "bad value") (parseStatus vs)
|
|
||||||
start _ = giveup "Wrong number of parameters"
|
|
||||||
|
|
||||||
perform :: Key -> UUID -> LogStatus -> CommandPerform
|
perform :: Key -> UUID -> LogStatus -> CommandPerform
|
||||||
perform k u s = next $ do
|
perform k u s = next $ do
|
||||||
|
|
|
@ -14,6 +14,13 @@ the specified key's content is present in a remote with the specified uuid.
|
||||||
Use 1 to indicate the key is present, or 0 to indicate the key is
|
Use 1 to indicate the key is present, or 0 to indicate the key is
|
||||||
not present.
|
not present.
|
||||||
|
|
||||||
|
# OPTIONS
|
||||||
|
|
||||||
|
* `--batch`
|
||||||
|
|
||||||
|
Enables batch mode, in which lines are read from stdin.
|
||||||
|
The line format is "key uuid [1|0]"
|
||||||
|
|
||||||
# SEE ALSO
|
# SEE ALSO
|
||||||
|
|
||||||
[[git-annex]](1)
|
[[git-annex]](1)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue