summaryrefslogtreecommitdiff
path: root/Command/InitRemote.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2011-05-28 21:58:48 -0400
committerGravatar Joey Hess <joey@kitenet.net>2011-05-28 21:58:48 -0400
commitfdead6b9bb0883dd982e72e955fc58dee844f2ca (patch)
treeb294be18891e62189ae2eb77dfb15dd8c9729300 /Command/InitRemote.hs
parenta19d81a42e4af0e8fc2ad0c09f1ebd72fb98cdd4 (diff)
improve error message when no remote name is specified
list available remotes in case user wanted to use or change one of them
Diffstat (limited to 'Command/InitRemote.hs')
-rw-r--r--Command/InitRemote.hs16
1 files changed, 15 insertions, 1 deletions
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