summaryrefslogtreecommitdiff
path: root/CmdLine.hs
diff options
context:
space:
mode:
Diffstat (limited to 'CmdLine.hs')
-rw-r--r--CmdLine.hs41
1 files changed, 41 insertions, 0 deletions
diff --git a/CmdLine.hs b/CmdLine.hs
new file mode 100644
index 000000000..79bd55cd9
--- /dev/null
+++ b/CmdLine.hs
@@ -0,0 +1,41 @@
+{- git-annex command line
+ -
+ - TODO: This is very rough and stupid; I would like to use
+ - System.Console.CmdArgs.Implicit but it is not yet packaged in Debian.
+ -}
+
+module CmdLine where
+
+import System.Console.GetOpt
+import Types
+import Annex
+
+data Flag = Add FilePath | Push String | Pull String |
+ Want FilePath | Get (Maybe FilePath) | Drop FilePath
+ deriving Show
+
+options :: [OptDescr Flag]
+options =
+ [ Option ['a'] ["add"] (ReqArg Add "FILE") "add file to annex"
+ , Option ['p'] ["push"] (ReqArg Push "REPO") "push annex to repo"
+ , Option ['P'] ["pull"] (ReqArg Pull "REPO") "pull annex from repo"
+ , Option ['w'] ["want"] (ReqArg Want "FILE") "request file contents"
+ , Option ['g'] ["get"] (OptArg Get "FILE") "transfer file contents"
+ , Option ['d'] ["drop"] (ReqArg Drop "FILE") "indicate file content not needed"
+ ]
+
+argvToFlags argv = do
+ case getOpt Permute options argv of
+ -- no options? add listed files
+ ([],p,[] ) -> return $ map (\f -> Add f) p
+ -- all options parsed, return flags
+ (o,[],[] ) -> return o
+ -- error case
+ (_,n,errs) -> ioError (userError (concat errs ++ usageInfo header options))
+ where header = "Usage: git-annex [option] file"
+
+dispatch :: Flag -> [Backend] -> GitRepo -> IO ()
+dispatch flag backends repo = do
+ case (flag) of
+ Add f -> annexFile backends repo f
+ _ -> error "not implemented"