enableremote: List uuids and descriptions of remotes that can be enabled, and accept either the uuid or the description in leu if the name.

This commit is contained in:
Joey Hess 2015-10-26 14:55:40 -04:00
parent 016904f424
commit 640dba43b6
Failed to extract signature
7 changed files with 75 additions and 25 deletions

View file

@ -12,6 +12,8 @@ import Command
import qualified Logs.Remote
import qualified Types.Remote as R
import qualified Annex.SpecialRemote
import qualified Remote
import Logs.UUID
import qualified Data.Map as M
@ -25,12 +27,19 @@ seek :: CmdParams -> CommandSeek
seek = withWords start
start :: [String] -> CommandStart
start [] = unknownNameError "Specify the name of the special remote to enable."
start [] = unknownNameError "Specify the special remote to enable."
start (name:ws) = go =<< Annex.SpecialRemote.findExisting name
where
config = Logs.Remote.keyValToConfig ws
go Nothing = unknownNameError "Unknown special remote name."
go Nothing = do
m <- Annex.SpecialRemote.specialRemoteMap
confm <- Logs.Remote.readRemoteLog
v <- Remote.nameToUUID' name
case v of
Right u | u `M.member` m ->
go (Just (u, fromMaybe M.empty (M.lookup u confm)))
_ -> unknownNameError "Unknown special remote."
go (Just (u, c)) = do
let fullconfig = config `M.union` c
t <- either error return (Annex.SpecialRemote.findType fullconfig)
@ -39,11 +48,14 @@ start (name:ws) = go =<< Annex.SpecialRemote.findExisting name
unknownNameError :: String -> Annex a
unknownNameError prefix = do
names <- Annex.SpecialRemote.remoteNames
error $ prefix ++ "\n" ++
if null names
then "(No special remotes are currently known; perhaps use initremote instead?)"
else "Known special remotes: " ++ unwords names
m <- Annex.SpecialRemote.specialRemoteMap
descm <- M.unionWith Remote.addName <$> uuidMap <*> pure m
msg <- if M.null m
then pure "(No special remotes are currently known; perhaps use initremote instead?)"
else Remote.prettyPrintUUIDsDescs
"known special remotes"
descm (M.keys m)
error $ prefix ++ "\n" ++ msg
perform :: RemoteType -> UUID -> R.RemoteConfig -> CommandPerform
perform t u c = do