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
|
2023-05-04 20:03:54 +00:00
|
|
|
cmd = noCommit $ withAnnexOptions [jsonOptions] $
|
2015-07-08 19:08:02 +00:00
|
|
|
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
|
2022-01-26 16:59:55 +00:00
|
|
|
Batch fmt -> batchOnly Nothing (params o) $
|
|
|
|
batchInput fmt
|
|
|
|
(pure . parseKeyStatus . words)
|
|
|
|
(batchCommandAction . uncurry start)
|
2020-09-14 20:49:33 +00:00
|
|
|
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
|
2024-08-23 20:35:12 +00:00
|
|
|
logChange NoLiveUpdate k u s
|
2014-12-29 19:16:40 +00:00
|
|
|
return True
|