summaryrefslogtreecommitdiff
path: root/Command/InitRemote.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2011-05-15 02:49:43 -0400
committerGravatar Joey Hess <joey@kitenet.net>2011-05-15 03:38:08 -0400
commitcad0e1c8b7eb21f8dceca8dd9fa3bc1d1aa7eabd (patch)
treeb6be12dc1cc83a35ca7d89a862d85e6d71c38572 /Command/InitRemote.hs
parentefa7f544050c0d5be6bc1b0fc0125278e475c213 (diff)
simplified a bunch of Maybe handling
Diffstat (limited to 'Command/InitRemote.hs')
-rw-r--r--Command/InitRemote.hs17
1 files changed, 9 insertions, 8 deletions
diff --git a/Command/InitRemote.hs b/Command/InitRemote.hs
index eda50ee5d..261ccdc8b 100644
--- a/Command/InitRemote.hs
+++ b/Command/InitRemote.hs
@@ -68,11 +68,11 @@ cleanup u c = do
findByName :: String -> Annex (UUID, RemoteClass.RemoteConfig)
findByName name = do
m <- Remote.readRemoteLog
- case findByName' name m of
- Just i -> return i
- Nothing -> do
+ maybe generate return $ findByName' name m
+ where
+ generate = do
uuid <- liftIO $ genUUID
- return $ (uuid, M.insert nameKey name M.empty)
+ return (uuid, M.insert nameKey name M.empty)
findByName' :: String -> M.Map UUID RemoteClass.RemoteConfig -> Maybe (UUID, RemoteClass.RemoteConfig)
findByName' n m = if null matches then Nothing else Just $ head matches
@@ -86,12 +86,13 @@ findByName' n m = if null matches then Nothing else Just $ head matches
{- find the specified remote type -}
findType :: RemoteClass.RemoteConfig -> Annex (RemoteClass.RemoteType Annex)
-findType config =
- case M.lookup typeKey config of
- Nothing -> error "Specify the type of remote with type="
- Just s -> case filter (\i -> RemoteClass.typename i == s) Remote.remoteTypes of
+findType config = maybe unspecified specified $ M.lookup typeKey config
+ where
+ unspecified = error "Specify the type of remote with type="
+ specified s = case filter (findtype s) Remote.remoteTypes of
[] -> error $ "Unknown remote type " ++ s
(t:_) -> return t
+ findtype s i = RemoteClass.typename i == s
{- The name of a configured remote is stored in its config using this key. -}
nameKey :: String