summaryrefslogtreecommitdiff
path: root/Command/InitRemote.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2011-12-15 18:11:42 -0400
committerGravatar Joey Hess <joey@kitenet.net>2011-12-15 18:19:36 -0400
commit95d2391f58ae240e7100f0d5488dd7246f71f3bb (patch)
treef33f21904ae7be4d40b70bab1e2a68fd4eef5526 /Command/InitRemote.hs
parentb7e0d39abbc9a09c21c6f0103ad6c9f4547f81fe (diff)
more partial function removal
Left a few Prelude.head's in where it was checked not null and too hard to remove, etc.
Diffstat (limited to 'Command/InitRemote.hs')
-rw-r--r--Command/InitRemote.hs25
1 files changed, 9 insertions, 16 deletions
diff --git a/Command/InitRemote.hs b/Command/InitRemote.hs
index 600e17eb8..1e6bc2ef1 100644
--- a/Command/InitRemote.hs
+++ b/Command/InitRemote.hs
@@ -25,9 +25,13 @@ seek :: [CommandSeek]
seek = [withWords start]
start :: [String] -> CommandStart
-start ws = do
- when (null ws) needname
-
+start [] = do
+ names <- remoteNames
+ error $ "Specify a name for the remote. " ++
+ if null names
+ then ""
+ else "Either a new name, or one of these existing special remotes: " ++ join " " names
+start (name:ws) = do
(u, c) <- findByName name
let fullconfig = config `M.union` c
t <- findType fullconfig
@@ -36,15 +40,7 @@ start ws = do
next $ perform t u $ M.union config c
where
- name = head ws
- config = Logs.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
-
+ config = Logs.Remote.keyValToConfig ws
perform :: R.RemoteType Annex -> UUID -> R.RemoteConfig -> CommandPerform
perform t u c = do
@@ -67,11 +63,8 @@ findByName name = do
return (uuid, M.insert nameKey name M.empty)
findByName' :: String -> M.Map UUID R.RemoteConfig -> Maybe (UUID, R.RemoteConfig)
-findByName' n m
- | null matches = Nothing
- | otherwise = Just $ head matches
+findByName' n = headMaybe . filter (matching . snd) . M.toList
where
- matches = filter (matching . snd) $ M.toList m
matching c = case M.lookup nameKey c of
Nothing -> False
Just n'