From fdead6b9bb0883dd982e72e955fc58dee844f2ca Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sat, 28 May 2011 21:58:48 -0400 Subject: improve error message when no remote name is specified list available remotes in case user wanted to use or change one of them --- Command/InitRemote.hs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'Command/InitRemote.hs') diff --git a/Command/InitRemote.hs b/Command/InitRemote.hs index ad0718e38..460f14de2 100644 --- a/Command/InitRemote.hs +++ b/Command/InitRemote.hs @@ -10,6 +10,8 @@ module Command.InitRemote where import qualified Data.Map as M import Control.Monad (when) import Control.Monad.State (liftIO) +import Data.Maybe +import Data.String.Utils import Command import qualified Annex @@ -32,7 +34,7 @@ seek = [withWords start] start :: CommandStartWords start ws = notBareRepo $ do - when (null ws) $ error "Specify a name for the remote" + when (null ws) $ needname (u, c) <- findByName name let fullconfig = M.union config c @@ -44,6 +46,13 @@ start ws = notBareRepo $ do where name = head ws config = Remote.keyValToConfig $ tail ws + needname = do + let err s = error $ "Specify a name for the remote. " ++ s + names <- remoteNames + if null names + then err "" + else err $ "Either a new name, or one of these existing special remotes: " ++ join " " names + perform :: RemoteClass.RemoteType Annex -> UUID -> RemoteClass.RemoteConfig -> CommandPerform perform t u c = do @@ -83,6 +92,11 @@ findByName' n m = if null matches then Nothing else Just $ head matches | n' == n -> True | otherwise -> False +remoteNames :: Annex [String] +remoteNames = do + m <- Remote.readRemoteLog + return $ catMaybes $ map ((M.lookup nameKey) . snd) $ M.toList m + {- find the specified remote type -} findType :: RemoteClass.RemoteConfig -> Annex (RemoteClass.RemoteType Annex) findType config = maybe unspecified specified $ M.lookup typeKey config -- cgit v1.2.3