2014-12-29 19:16:40 +00:00
|
|
|
{- git-annex command
|
|
|
|
-
|
2015-01-21 16:50:09 +00:00
|
|
|
- Copyright 2014 Joey Hess <id@joeyh.name>
|
2014-12-29 19:16:40 +00:00
|
|
|
-
|
2019-03-13 19:48:14 +00:00
|
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
2014-12-29 19:16:40 +00:00
|
|
|
-}
|
|
|
|
|
|
|
|
module Command.SetPresentKey where
|
|
|
|
|
|
|
|
import Command
|
|
|
|
import Logs.Location
|
|
|
|
import Logs.Presence.Pure
|
|
|
|
|
2015-07-08 16:33:27 +00:00
|
|
|
cmd :: Command
|
2015-07-08 19:08:02 +00:00
|
|
|
cmd = noCommit $
|
|
|
|
command "setpresentkey" SectionPlumbing
|
|
|
|
"change records of where key is present"
|
|
|
|
(paramPair paramKey (paramPair paramUUID "[1|0]"))
|
2018-05-27 18:56:14 +00:00
|
|
|
(seek <$$> optParser)
|
2014-12-29 19:16:40 +00:00
|
|
|
|
2018-05-27 18:56:14 +00:00
|
|
|
data SetPresentKeyOptions = SetPresentKeyOptions
|
|
|
|
{ params :: CmdParams
|
|
|
|
, batchOption :: BatchMode
|
|
|
|
}
|
2014-12-29 19:16:40 +00:00
|
|
|
|
2018-05-27 18:56:14 +00:00
|
|
|
optParser :: CmdParamsDesc -> Parser SetPresentKeyOptions
|
|
|
|
optParser desc = SetPresentKeyOptions
|
|
|
|
<$> cmdParams desc
|
2021-08-25 18:20:33 +00:00
|
|
|
<*> parseBatchOption False
|
2018-05-27 18:56:14 +00:00
|
|
|
|
|
|
|
seek :: SetPresentKeyOptions -> CommandSeek
|
|
|
|
seek o = case batchOption o of
|
added -z
Added -z option to git-annex commands that use --batch, useful for
supporting filenames containing newlines.
It only controls input to --batch, the output will still be line delimited
unless --json or etc is used to get some other output. While git often
makes -z affect both input and output, I don't like trying them together,
and making it affect output would have been a significant complication,
and also git-annex output is generally not intended to be machine parsed,
unless using --json or a format option.
Commands that take pairs like "file key" still separate them with a space
in --batch mode. All such commands take care to support filenames with
spaces when parsing that, so there was no need to change it, and it would
have needed significant changes to the batch machinery to separate tose
with a null.
To make fromkey and registerurl support -z, I had to give them a --batch
option. The implicit batch mode they enter when not provided with input
parameters does not support -z as that would have complicated option
parsing. Seemed better to move these toward using the same --batch as
everything else, though the implicit batch mode can still be used.
This commit was sponsored by Ole-Morten Duesund on Patreon.
2018-09-20 20:09:21 +00:00
|
|
|
Batch fmt -> batchInput fmt
|
2020-04-15 20:04:05 +00:00
|
|
|
(pure . parseKeyStatus . words)
|
2020-09-14 20:49:33 +00:00
|
|
|
(batchCommandAction . uncurry start)
|
|
|
|
NoBatch -> either giveup (commandAction . start (SeekInput (params o)))
|
2018-05-27 18:56:14 +00:00
|
|
|
(parseKeyStatus $ params o)
|
|
|
|
|
|
|
|
data KeyStatus = KeyStatus Key UUID LogStatus
|
|
|
|
|
|
|
|
parseKeyStatus :: [String] -> Either String KeyStatus
|
|
|
|
parseKeyStatus (ks:us:vs:[]) = do
|
2019-01-14 17:17:47 +00:00
|
|
|
k <- maybe (Left "bad key") Right (deserializeKey ks)
|
2018-05-27 18:56:14 +00:00
|
|
|
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"
|
|
|
|
|
2020-09-14 20:49:33 +00:00
|
|
|
start :: SeekInput -> KeyStatus -> CommandStart
|
|
|
|
start si (KeyStatus k u s) = starting "setpresentkey" ai si $ perform k u s
|
|
|
|
where
|
|
|
|
ai = mkActionItem k
|
2014-12-29 19:16:40 +00:00
|
|
|
|
|
|
|
perform :: Key -> UUID -> LogStatus -> CommandPerform
|
2014-12-29 19:35:14 +00:00
|
|
|
perform k u s = next $ do
|
|
|
|
logChange k u s
|
2014-12-29 19:16:40 +00:00
|
|
|
return True
|