2010-10-10 22:05:37 +00:00
|
|
|
{- 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.
|
|
|
|
-}
|
|
|
|
|
2010-10-11 21:52:46 +00:00
|
|
|
module CmdLine (
|
|
|
|
argvToMode,
|
|
|
|
dispatch
|
|
|
|
) where
|
2010-10-10 22:05:37 +00:00
|
|
|
|
|
|
|
import System.Console.GetOpt
|
2010-10-12 20:20:41 +00:00
|
|
|
import Types
|
2010-10-10 22:05:37 +00:00
|
|
|
import Annex
|
|
|
|
|
2010-10-11 01:00:42 +00:00
|
|
|
data Mode = Add | Push | Pull | Want | Get | Drop | Unannex
|
2010-10-10 22:05:37 +00:00
|
|
|
deriving Show
|
|
|
|
|
2010-10-11 01:00:42 +00:00
|
|
|
options :: [OptDescr Mode]
|
2010-10-10 22:05:37 +00:00
|
|
|
options =
|
2010-10-11 01:00:42 +00:00
|
|
|
[ Option ['a'] ["add"] (NoArg Add) "add files to annex"
|
|
|
|
, Option ['p'] ["push"] (NoArg Push) "push annex to repos"
|
|
|
|
, Option ['P'] ["pull"] (NoArg Pull) "pull annex from repos"
|
|
|
|
, Option ['w'] ["want"] (NoArg Want) "request file contents"
|
|
|
|
, Option ['g'] ["get"] (NoArg Get) "transfer file contents"
|
|
|
|
, Option ['d'] ["drop"] (NoArg Drop) "indicate file contents not needed"
|
|
|
|
, Option ['u'] ["unannex"] (NoArg Unannex) "undo --add"
|
2010-10-10 22:05:37 +00:00
|
|
|
]
|
|
|
|
|
2010-10-11 01:00:42 +00:00
|
|
|
argvToMode argv = do
|
2010-10-10 22:05:37 +00:00
|
|
|
case getOpt Permute options argv of
|
2010-10-11 01:00:42 +00:00
|
|
|
-- default mode is Add
|
|
|
|
([],files,[]) -> return (Add, files)
|
|
|
|
-- one mode is normal case
|
|
|
|
(m:[],files,[]) -> return (m, files)
|
|
|
|
-- multiple modes is an error
|
|
|
|
(ms,files,[]) -> ioError (userError ("only one mode should be specified\n" ++ usageInfo header options))
|
2010-10-10 22:05:37 +00:00
|
|
|
-- error case
|
2010-10-11 01:00:42 +00:00
|
|
|
(_,files,errs) -> ioError (userError (concat errs ++ usageInfo header options))
|
|
|
|
where header = "Usage: git-annex [mode] file"
|
2010-10-10 22:05:37 +00:00
|
|
|
|
2010-10-11 01:00:42 +00:00
|
|
|
dispatch :: State -> Mode -> FilePath -> IO ()
|
2010-10-12 19:44:54 +00:00
|
|
|
dispatch state mode item = do
|
2010-10-11 01:00:42 +00:00
|
|
|
case (mode) of
|
2010-10-12 19:44:54 +00:00
|
|
|
Add -> annexFile state item
|
|
|
|
Push -> annexPushRepo state item
|
|
|
|
Pull -> annexPullRepo state item
|
|
|
|
Want -> annexWantFile state item
|
|
|
|
Get -> annexGetFile state item
|
|
|
|
Drop -> annexDropFile state item
|
|
|
|
Unannex -> unannexFile state item
|