git-annex/CmdLine.hs
2010-10-10 18:05:37 -04:00

41 lines
1.3 KiB
Haskell

{- 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"