From 5de4482c1b52ead223bc380b45fcc421e25a80a4 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 26 Oct 2015 14:55:40 -0400 Subject: enableremote: List uuids and descriptions of remotes that can be enabled, and accept either the uuid or the description in leu if the name. --- Command/EnableRemote.hs | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'Command/EnableRemote.hs') diff --git a/Command/EnableRemote.hs b/Command/EnableRemote.hs index 84216dd78..b3ba451c2 100644 --- a/Command/EnableRemote.hs +++ b/Command/EnableRemote.hs @@ -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 -- cgit v1.2.3