summaryrefslogtreecommitdiff
path: root/Command.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2010-11-04 13:28:49 -0400
committerGravatar Joey Hess <joey@kitenet.net>2010-11-04 13:28:49 -0400
commitdf4b461df1bf70016ffa02d08e822067f8544a63 (patch)
tree88b2a92daec404e607f0fd777c19d440ad6b5895 /Command.hs
parent0eae5b806c76b0fa3e21fbae6e5f2d9a39a04cce (diff)
refactor
Diffstat (limited to 'Command.hs')
-rw-r--r--Command.hs40
1 files changed, 39 insertions, 1 deletions
diff --git a/Command.hs b/Command.hs
index 3d1e75e5f..47c73370f 100644
--- a/Command.hs
+++ b/Command.hs
@@ -8,7 +8,9 @@
module Command where
import Types
-import Backend
+import qualified Backend
+import Core
+import qualified Annex
{- A subcommand runs in four stages.
-
@@ -35,6 +37,42 @@ type SubCmdStartString = String -> SubCmdStart
type SubCmdSeekBackendFiles = SubCmdStartBackendFile -> SubCmdSeek
type SubCmdStartBackendFile = (FilePath, Maybe Backend) -> SubCmdStart
+data SubCommand = SubCommand {
+ subcmdname :: String,
+ subcmdparams :: String,
+ subcmdseek :: SubCmdSeek,
+ subcmddesc :: String
+}
+
+{- Prepares a list of actions to run to perform a subcommand, based on
+ - the parameters passed to it. -}
+prepSubCmd :: SubCommand -> AnnexState -> [String] -> IO [Annex Bool]
+prepSubCmd SubCommand { subcmdseek = seek } state params = do
+ list <- Annex.eval state $ seek params
+ return $ map (\a -> doSubCmd a) list
+
+{- Runs a subcommand through the start, perform and cleanup stages -}
+doSubCmd :: SubCmdStart -> SubCmdCleanup
+doSubCmd 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 do
+ showEndOk
+ return True
+ else do
+ showEndFail
+ return False
+
notAnnexed :: FilePath -> Annex (Maybe a) -> Annex (Maybe a)
notAnnexed file a = do
r <- Backend.lookupFile file