summaryrefslogtreecommitdiff
path: root/Command.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.hs
parentefa7f544050c0d5be6bc1b0fc0125278e475c213 (diff)
simplified a bunch of Maybe handling
Diffstat (limited to 'Command.hs')
-rw-r--r--Command.hs26
1 files changed, 7 insertions, 19 deletions
diff --git a/Command.hs b/Command.hs
index 0e3958c18..c6c1fe5c5 100644
--- a/Command.hs
+++ b/Command.hs
@@ -14,6 +14,7 @@ import Control.Monad (filterM, liftM, when)
import System.Path.WildMatch
import Text.Regex.PCRE.Light.Char8
import Data.List
+import Data.Maybe
import Types
import qualified Backend
@@ -106,18 +107,10 @@ doCommand start = do
return c
notAnnexed :: FilePath -> Annex (Maybe a) -> Annex (Maybe a)
-notAnnexed file a = do
- r <- Backend.lookupFile file
- case r of
- Just _ -> return Nothing
- Nothing -> a
+notAnnexed file a = maybe a (const $ return Nothing) =<< Backend.lookupFile file
isAnnexed :: FilePath -> ((Key, Backend Annex) -> Annex (Maybe a)) -> Annex (Maybe a)
-isAnnexed file a = do
- r <- Backend.lookupFile file
- case r of
- Just v -> a v
- Nothing -> return Nothing
+isAnnexed file a = maybe (return Nothing) a =<< Backend.lookupFile file
notBareRepo :: Annex a -> Annex a
notBareRepo a = do
@@ -183,9 +176,7 @@ withFilesUnlocked' typechanged a params = do
withKeys :: CommandSeekKeys
withKeys a params = return $ map a $ map parse params
where
- parse p = case readKey p of
- Just k -> k
- Nothing -> error "bad key"
+ parse p = maybe (error "bad key") id $ readKey p
withTempFile :: CommandSeekStrings
withTempFile a params = return $ map a params
withNothing :: CommandSeekNothing
@@ -206,9 +197,7 @@ filterFiles l = do
else return $ filter (notExcluded $ wildsRegex exclude) l'
where
notState f = not $ stateDir `isPrefixOf` f
- notExcluded r f = case match r f [] of
- Nothing -> True
- Just _ -> False
+ notExcluded r f = isJust $ match r f []
wildsRegex :: [String] -> Regex
wildsRegex ws = compile regex []
@@ -257,11 +246,10 @@ cmdlineKey = do
case k of
Nothing -> nokey
Just "" -> nokey
- Just kstring -> case readKey kstring of
- Nothing -> error "bad key"
- Just key -> return key
+ Just kstring -> maybe badkey return $ readKey kstring
where
nokey = error "please specify the key with --key"
+ badkey = error "bad key"
{- Given an original list of files, and an expanded list derived from it,
- ensures that the original list's ordering is preserved.