2010-11-02 23:04:24 +00:00
|
|
|
{- git-annex command line
|
|
|
|
-
|
|
|
|
- Copyright 2010 Joey Hess <joey@kitenet.net>
|
|
|
|
-
|
|
|
|
- Licensed under the GNU GPL version 3 or higher.
|
|
|
|
-}
|
|
|
|
|
|
|
|
module CmdLine (parseCmd) where
|
|
|
|
|
|
|
|
import System.Console.GetOpt
|
2010-11-11 22:54:52 +00:00
|
|
|
import Control.Monad (when)
|
2010-12-08 18:07:49 +00:00
|
|
|
import Control.Monad.State (liftIO)
|
2010-11-02 23:04:24 +00:00
|
|
|
|
|
|
|
import qualified Annex
|
|
|
|
import Types
|
|
|
|
|
|
|
|
import Command
|
|
|
|
import qualified Command.Add
|
|
|
|
import qualified Command.Unannex
|
|
|
|
import qualified Command.Drop
|
|
|
|
import qualified Command.Move
|
2010-11-27 21:02:53 +00:00
|
|
|
import qualified Command.Copy
|
2010-11-02 23:04:24 +00:00
|
|
|
import qualified Command.Get
|
|
|
|
import qualified Command.FromKey
|
|
|
|
import qualified Command.DropKey
|
|
|
|
import qualified Command.SetKey
|
|
|
|
import qualified Command.Fix
|
|
|
|
import qualified Command.Init
|
2010-11-04 17:37:06 +00:00
|
|
|
import qualified Command.Fsck
|
2010-11-15 20:35:06 +00:00
|
|
|
import qualified Command.Unused
|
2010-11-15 22:04:19 +00:00
|
|
|
import qualified Command.DropUnused
|
2010-11-09 19:59:49 +00:00
|
|
|
import qualified Command.Unlock
|
|
|
|
import qualified Command.Lock
|
2010-11-10 14:49:35 +00:00
|
|
|
import qualified Command.PreCommit
|
2010-11-14 16:35:05 +00:00
|
|
|
import qualified Command.Find
|
2010-12-03 04:33:41 +00:00
|
|
|
import qualified Command.Uninit
|
2010-11-02 23:04:24 +00:00
|
|
|
|
|
|
|
subCmds :: [SubCommand]
|
2010-11-06 21:06:19 +00:00
|
|
|
subCmds =
|
2010-11-11 22:54:52 +00:00
|
|
|
[ SubCommand "add" path Command.Add.seek
|
2010-11-06 21:06:19 +00:00
|
|
|
"add files to annex"
|
2010-11-11 22:54:52 +00:00
|
|
|
, SubCommand "get" path Command.Get.seek
|
2010-11-06 21:06:19 +00:00
|
|
|
"make content of annexed files available"
|
2010-11-11 22:54:52 +00:00
|
|
|
, SubCommand "drop" path Command.Drop.seek
|
2010-11-06 21:06:19 +00:00
|
|
|
"indicate content of files not currently wanted"
|
2010-11-11 22:54:52 +00:00
|
|
|
, SubCommand "move" path Command.Move.seek
|
2010-11-27 21:02:53 +00:00
|
|
|
"move content of files to/from another repository"
|
|
|
|
, SubCommand "copy" path Command.Copy.seek
|
|
|
|
"copy content of files to/from another repository"
|
2010-11-11 22:54:52 +00:00
|
|
|
, SubCommand "unlock" path Command.Unlock.seek
|
2010-11-09 19:59:49 +00:00
|
|
|
"unlock files for modification"
|
2010-11-11 22:54:52 +00:00
|
|
|
, SubCommand "edit" path Command.Unlock.seek
|
2010-11-10 17:28:04 +00:00
|
|
|
"same as unlock"
|
2010-11-11 22:54:52 +00:00
|
|
|
, SubCommand "lock" path Command.Lock.seek
|
2010-11-09 19:59:49 +00:00
|
|
|
"undo unlock command"
|
2010-11-11 22:54:52 +00:00
|
|
|
, SubCommand "init" desc Command.Init.seek
|
2010-11-06 21:06:19 +00:00
|
|
|
"initialize git-annex with repository description"
|
2010-11-11 22:54:52 +00:00
|
|
|
, SubCommand "unannex" path Command.Unannex.seek
|
2010-11-06 21:06:19 +00:00
|
|
|
"undo accidential add command"
|
2010-12-03 04:33:41 +00:00
|
|
|
, SubCommand "uninit" path Command.Uninit.seek
|
|
|
|
"de-initialize git-annex and clean out repository"
|
2010-11-11 22:54:52 +00:00
|
|
|
, SubCommand "pre-commit" path Command.PreCommit.seek
|
2010-11-10 14:49:35 +00:00
|
|
|
"run by git pre-commit hook"
|
2010-11-11 22:54:52 +00:00
|
|
|
, SubCommand "fromkey" key Command.FromKey.seek
|
2010-11-06 21:06:19 +00:00
|
|
|
"adds a file using a specific key"
|
2010-11-11 22:54:52 +00:00
|
|
|
, SubCommand "dropkey" key Command.DropKey.seek
|
2010-11-06 21:06:19 +00:00
|
|
|
"drops annexed content for specified keys"
|
2010-11-11 22:54:52 +00:00
|
|
|
, SubCommand "setkey" key Command.SetKey.seek
|
2010-11-06 21:06:19 +00:00
|
|
|
"sets annexed content for a key using a temp file"
|
2010-11-11 22:54:52 +00:00
|
|
|
, SubCommand "fix" path Command.Fix.seek
|
2010-11-06 21:06:19 +00:00
|
|
|
"fix up symlinks to point to annexed content"
|
2010-11-13 18:59:27 +00:00
|
|
|
, SubCommand "fsck" maybepath Command.Fsck.seek
|
|
|
|
"check for problems"
|
2010-11-15 20:35:06 +00:00
|
|
|
, SubCommand "unused" nothing Command.Unused.seek
|
|
|
|
"look for unused file content"
|
2010-11-15 22:04:19 +00:00
|
|
|
, SubCommand "dropunused" number Command.DropUnused.seek
|
|
|
|
"drop unused file content"
|
2010-11-14 16:35:05 +00:00
|
|
|
, SubCommand "find" maybepath Command.Find.seek
|
|
|
|
"lists available files"
|
2010-11-02 23:04:24 +00:00
|
|
|
]
|
|
|
|
where
|
|
|
|
path = "PATH ..."
|
2010-11-13 18:59:27 +00:00
|
|
|
maybepath = "[PATH ...]"
|
2010-11-02 23:04:24 +00:00
|
|
|
key = "KEY ..."
|
|
|
|
desc = "DESCRIPTION"
|
2010-11-15 22:04:19 +00:00
|
|
|
number = "NUMBER ..."
|
2010-11-15 20:35:06 +00:00
|
|
|
nothing = ""
|
2010-11-02 23:04:24 +00:00
|
|
|
|
|
|
|
-- Each dashed command-line option results in generation of an action
|
|
|
|
-- in the Annex monad that performs the necessary setting.
|
|
|
|
options :: [OptDescr (Annex ())]
|
|
|
|
options = [
|
|
|
|
Option ['f'] ["force"] (NoArg (storebool "force" True))
|
|
|
|
"allow actions that may lose annexed data"
|
|
|
|
, Option ['q'] ["quiet"] (NoArg (storebool "quiet" True))
|
|
|
|
"avoid verbose output"
|
|
|
|
, Option ['v'] ["verbose"] (NoArg (storebool "quiet" False))
|
|
|
|
"allow verbose output"
|
|
|
|
, Option ['b'] ["backend"] (ReqArg (storestring "backend") "NAME")
|
|
|
|
"specify default key-value backend to use"
|
|
|
|
, Option ['k'] ["key"] (ReqArg (storestring "key") "KEY")
|
|
|
|
"specify a key to use"
|
|
|
|
, Option ['t'] ["to"] (ReqArg (storestring "torepository") "REPOSITORY")
|
|
|
|
"specify to where to transfer content"
|
|
|
|
, Option ['f'] ["from"] (ReqArg (storestring "fromrepository") "REPOSITORY")
|
|
|
|
"specify from where to transfer content"
|
2010-12-08 18:07:49 +00:00
|
|
|
, Option ['x'] ["exclude"] (ReqArg (storestring "exclude") "GLOB")
|
|
|
|
"skip files matching the glob pattern"
|
2010-11-02 23:04:24 +00:00
|
|
|
]
|
|
|
|
where
|
|
|
|
storebool n b = Annex.flagChange n $ FlagBool b
|
|
|
|
storestring n s = Annex.flagChange n $ FlagString s
|
|
|
|
|
|
|
|
header :: String
|
2010-11-04 17:40:00 +00:00
|
|
|
header = "Usage: git-annex subcommand [option ..]"
|
2010-11-02 23:04:24 +00:00
|
|
|
|
|
|
|
{- Usage message with lists of options and subcommands. -}
|
|
|
|
usage :: String
|
|
|
|
usage = usageInfo header options ++ "\nSubcommands:\n" ++ cmddescs
|
|
|
|
where
|
2010-11-06 21:06:19 +00:00
|
|
|
cmddescs = unlines $ map (indent . showcmd) subCmds
|
2010-11-02 23:04:24 +00:00
|
|
|
showcmd c =
|
2010-11-06 21:06:19 +00:00
|
|
|
subcmdname c ++
|
|
|
|
pad 11 (subcmdname c) ++
|
|
|
|
subcmdparams c ++
|
|
|
|
pad 13 (subcmdparams c) ++
|
|
|
|
subcmddesc c
|
2010-11-02 23:04:24 +00:00
|
|
|
indent l = " " ++ l
|
2010-11-06 21:06:19 +00:00
|
|
|
pad n s = replicate (n - length s) ' '
|
2010-11-02 23:04:24 +00:00
|
|
|
|
2010-12-08 18:07:49 +00:00
|
|
|
{- Parses command line, stores configure flags, and returns a
|
|
|
|
- list of actions to be run in the Annex monad. -}
|
|
|
|
parseCmd :: [String] -> Annex [Annex Bool]
|
|
|
|
parseCmd argv = do
|
|
|
|
(flags, params) <- liftIO $ getopt
|
2010-11-02 23:04:24 +00:00
|
|
|
when (null params) $ error usage
|
2010-11-06 21:06:19 +00:00
|
|
|
case lookupCmd (head params) of
|
2010-11-02 23:04:24 +00:00
|
|
|
[] -> error usage
|
|
|
|
[subcommand] -> do
|
2010-12-08 18:07:49 +00:00
|
|
|
_ <- sequence flags
|
|
|
|
prepSubCmd subcommand (drop 1 params)
|
2010-11-02 23:04:24 +00:00
|
|
|
_ -> error "internal error: multiple matching subcommands"
|
|
|
|
where
|
|
|
|
getopt = case getOpt Permute options argv of
|
|
|
|
(flags, params, []) -> return (flags, params)
|
|
|
|
(_, _, errs) -> ioError (userError (concat errs ++ usage))
|
|
|
|
lookupCmd cmd = filter (\c -> cmd == subcmdname c) subCmds
|