convert Dead, and allow multiple --key options

This commit is contained in:
Joey Hess 2015-07-13 10:26:54 -04:00
parent adec382bc2
commit 3d8a8e9792
3 changed files with 17 additions and 13 deletions

View file

@ -9,26 +9,29 @@ module Command.Dead where
import Command
import Common.Annex
import qualified Annex
import Types.TrustLevel
import Types.Key
import Command.Trust (trustCommand)
import Logs.Location
import Remote (keyLocations)
import Git.Types
cmd :: Command
cmd = withOptions [keyOption] $
command "dead" SectionSetup "hide a lost repository or key"
(paramRepeating paramRemote) (withParams seek)
cmd = command "dead" SectionSetup "hide a lost repository or key"
(paramRepeating paramRemote) (seek <$$> optParser)
seek :: CmdParams -> CommandSeek
seek ps = maybe (trustCommand "dead" DeadTrusted ps) (flip seekKey ps)
=<< Annex.getField "key"
data DeadOptions = DeadRemotes [RemoteName] | DeadKeys [Key]
seekKey :: String -> CmdParams -> CommandSeek
seekKey ks = case file2key ks of
Nothing -> error "Invalid key"
Just key -> withNothing (startKey key)
optParser :: CmdParamsDesc -> Parser DeadOptions
optParser desc = (DeadRemotes <$> cmdParams desc)
<|> (DeadKeys <$> many (option (str >>= parseKey)
( long "key" <> metavar paramKey
<> help "keys whose content has been irretrievably lost"
)))
seek :: DeadOptions -> CommandSeek
seek (DeadRemotes rs) = trustCommand "dead" DeadTrusted rs
seek (DeadKeys ks) = seekActions $ pure $ map startKey ks
startKey :: Key -> CommandStart
startKey key = do