summaryrefslogtreecommitdiff
path: root/Commands.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2010-10-16 14:58:35 -0400
committerGravatar Joey Hess <joey@kitenet.net>2010-10-16 14:58:35 -0400
commite80160380a16fbeb38f21f4683917b49a9221a91 (patch)
treef309eb102278191039a6f9690f72e579f7ceb1f0 /Commands.hs
parentbfa581a218719c46dbc19a212a005b0cf2e145c2 (diff)
now finds files in git or not depending on what command wants
Diffstat (limited to 'Commands.hs')
-rw-r--r--Commands.hs56
1 files changed, 39 insertions, 17 deletions
diff --git a/Commands.hs b/Commands.hs
index 3d85b12b9..a2535001e 100644
--- a/Commands.hs
+++ b/Commands.hs
@@ -21,35 +21,57 @@ import LocationLog
import Types
import Core
import qualified Remotes
+import qualified BackendTypes
+
+data CmdWants = FilesInGit | FilesNotInGit | RepoName
+data Command = Command {
+ cmdname :: String,
+ cmdaction :: (String -> Annex ()),
+ cmdwants :: CmdWants
+}
+
+cmds :: [Command]
+cmds = [ (Command "add" addCmd FilesNotInGit)
+ , (Command "get" getCmd FilesInGit)
+ , (Command "drop" dropCmd FilesInGit)
+ , (Command "want" wantCmd FilesInGit)
+ , (Command "push" pushCmd RepoName)
+ , (Command "pull" pullCmd RepoName)
+ , (Command "unannex" unannexCmd FilesInGit)
+ ]
+
+{- Finds the type of parameters a command wants, from among the passed
+ - parameter list. -}
+findWanted :: CmdWants -> [String] -> Git.Repo -> IO [String]
+findWanted FilesNotInGit params repo = do
+ files <- mapM (Git.notInRepo repo) params
+ return $ foldl (++) [] files
+findWanted FilesInGit params repo = do
+ files <- mapM (Git.inRepo repo) params
+ return $ foldl (++) [] files
+findWanted RepoName params _ = do
+ return $ params
{- Parses command line and returns a list of flags and a list of
- actions to be run in the Annex monad. -}
-parseCmd :: [String] -> IO ([Flag], [Annex ()])
-parseCmd argv = do
+parseCmd :: [String] -> AnnexState -> IO ([Flag], [Annex ()])
+parseCmd argv state = do
(flags, params) <- getopt
case (length params) of
0 -> error header
_ -> case (lookupCmd (params !! 0)) of
[] -> error header
- [(_,cmd)] -> do
- let locs = drop 1 params
- files <- mapM recurseFiles locs
- return (flags, map cmd $ foldl (++) [] files)
+ [Command _ action want] -> do
+ f <- findWanted want (drop 1 params)
+ (BackendTypes.repo state)
+ return (flags, map action f)
where
getopt = case getOpt Permute options argv of
- (flags, nonopts, []) -> return (flags, nonopts)
+ (flags, params, []) -> return (flags, params)
(_, _, errs) -> ioError (userError (concat errs ++ usageInfo header options))
- lookupCmd cmd = filter (\(c, a) -> c == cmd) cmds
- cmds = [ ("add", addCmd)
- , ("get", getCmd)
- , ("drop", dropCmd)
- , ("want", wantCmd)
- , ("push", pushCmd)
- , ("pull", pullCmd)
- , ("unannex", unannexCmd)
- ]
+ lookupCmd cmd = filter (\c -> cmd == cmdname c) cmds
header = "Usage: git-annex [" ++
- (join "|" $ map fst cmds) ++ "] file ..."
+ (join "|" $ map cmdname cmds) ++ "] file ..."
options = [ Option ['f'] ["force"] (NoArg Force) "allow actions that may loose annexed data" ]
{- Annexes a file, storing it in a backend, and then moving it into