summaryrefslogtreecommitdiff
path: root/Command.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2011-05-15 12:25:58 -0400
committerGravatar Joey Hess <joey@kitenet.net>2011-05-15 12:25:58 -0400
commit3e15a8a791d15c166557fa18f240639891a8754f (patch)
treee4aab63486d489a0c4e78c0d31da6406f7f7a515 /Command.hs
parentcad0e1c8b7eb21f8dceca8dd9fa3bc1d1aa7eabd (diff)
Maybe reduction pass 2
Diffstat (limited to 'Command.hs')
-rw-r--r--Command.hs20
1 files changed, 6 insertions, 14 deletions
diff --git a/Command.hs b/Command.hs
index c6c1fe5c5..4f835a3ad 100644
--- a/Command.hs
+++ b/Command.hs
@@ -91,20 +91,12 @@ prepCommand Command { cmdseek = seek } params = do
{- Runs a command through the start, perform and cleanup stages -}
doCommand :: CommandStart -> CommandCleanup
-doCommand start = do
- s <- start
- case s of
- Nothing -> return True
- Just perform -> do
- p <- perform
- case p of
- Nothing -> do
- showEndFail
- return False
- Just cleanup -> do
- c <- cleanup
- if c then showEndOk else showEndFail
- return c
+doCommand = start
+ where
+ start = stage $ maybe (return True) perform
+ perform = stage $ maybe (showEndFail >> return False) cleanup
+ cleanup = stage $ \r -> showEndResult r >> return r
+ stage a b = b >>= a
notAnnexed :: FilePath -> Annex (Maybe a) -> Annex (Maybe a)
notAnnexed file a = maybe a (const $ return Nothing) =<< Backend.lookupFile file