git-annex/CmdLine/GitAnnex/Options.hs

102 lines
3.8 KiB
Haskell
Raw Normal View History

2013-03-27 17:51:24 +00:00
{- git-annex options
-
- Copyright 2010, 2013 Joey Hess <id@joeyh.name>
2013-03-27 17:51:24 +00:00
-
- Licensed under the GNU GPL version 3 or higher.
-}
2014-01-26 20:25:55 +00:00
module CmdLine.GitAnnex.Options where
2013-03-27 17:51:24 +00:00
import System.Console.GetOpt
import Common.Annex
import qualified Git.Config
import Git.Types
2013-03-27 17:51:24 +00:00
import Types.TrustLevel
import Types.NumCopies
import Types.Messages
2013-03-27 17:51:24 +00:00
import qualified Annex
import qualified Remote
import qualified Limit
import qualified Limit.Wanted
2014-01-26 20:25:55 +00:00
import CmdLine.Option
import CmdLine.Usage
2013-03-27 17:51:24 +00:00
2014-01-26 20:25:55 +00:00
gitAnnexOptions :: [Option]
gitAnnexOptions = commonOptions ++
2013-03-27 17:51:24 +00:00
[ Option ['N'] ["numcopies"] (ReqArg setnumcopies paramNumber)
"override default number of copies"
, Option [] ["trust"] (trustArg Trusted)
"override trust setting"
, Option [] ["semitrust"] (trustArg SemiTrusted)
"override trust setting back to default"
, Option [] ["untrust"] (trustArg UnTrusted)
"override trust setting to untrusted"
, Option ['c'] ["config"] (ReqArg setgitconfig "NAME=VALUE")
"override git configuration setting"
, Option ['x'] ["exclude"] (ReqArg Limit.addExclude paramGlob)
"skip files matching the glob pattern"
, Option ['I'] ["include"] (ReqArg Limit.addInclude paramGlob)
"limit to files matching the glob pattern"
2013-03-27 17:51:24 +00:00
, Option ['i'] ["in"] (ReqArg Limit.addIn paramRemote)
"match files present in a remote"
2013-03-27 17:51:24 +00:00
, Option ['C'] ["copies"] (ReqArg Limit.addCopies paramNumber)
"skip files with fewer copies"
, Option [] ["lackingcopies"] (ReqArg (Limit.addLackingCopies False) paramNumber)
"match files that need more copies"
, Option [] ["approxlackingcopies"] (ReqArg (Limit.addLackingCopies True) paramNumber)
"match files that need more copies (faster)"
2013-03-27 17:51:24 +00:00
, Option ['B'] ["inbackend"] (ReqArg Limit.addInBackend paramName)
"match files using a key-value backend"
2013-03-27 17:51:24 +00:00
, Option [] ["inallgroup"] (ReqArg Limit.addInAllGroup paramGroup)
"match files present in all remotes in a group"
2013-03-27 17:51:24 +00:00
, Option [] ["largerthan"] (ReqArg Limit.addLargerThan paramSize)
"match files larger than a size"
2013-03-27 17:51:24 +00:00
, Option [] ["smallerthan"] (ReqArg Limit.addSmallerThan paramSize)
"match files smaller than a size"
, Option [] ["metadata"] (ReqArg Limit.addMetaData "FIELD=VALUE")
"match files with attached metadata"
, Option [] ["want-get"] (NoArg Limit.Wanted.addWantGet)
2013-10-28 18:51:51 +00:00
"match files the repository wants to get"
, Option [] ["want-drop"] (NoArg Limit.Wanted.addWantDrop)
2013-10-28 18:51:51 +00:00
"match files the repository wants to drop"
2013-03-27 17:51:24 +00:00
, Option ['T'] ["time-limit"] (ReqArg Limit.addTimeLimit paramTime)
"stop after the specified amount of time"
, Option [] ["user-agent"] (ReqArg setuseragent paramName)
"override default User-Agent"
2013-03-27 17:51:24 +00:00
, Option [] ["trust-glacier"] (NoArg (Annex.setFlag "trustglacier"))
"Trust Amazon Glacier inventory"
2014-01-26 20:25:55 +00:00
] ++ matcherOptions
2013-03-27 17:51:24 +00:00
where
trustArg t = ReqArg (Remote.forceTrust t) paramRemote
2013-03-27 17:51:24 +00:00
setnumcopies v = maybe noop
(\n -> Annex.changeState $ \s -> s { Annex.forcenumcopies = Just $ NumCopies n })
2013-03-27 17:51:24 +00:00
(readish v)
setuseragent v = Annex.changeState $ \s -> s { Annex.useragent = Just v }
setgitconfig v = inRepo (Git.Config.store v)
>>= pure . (\r -> r { gitGlobalOpts = gitGlobalOpts r ++ [Param "-c", Param v] })
>>= Annex.changeGitRepo
keyOptions :: [Option]
keyOptions =
[ Option ['A'] ["all"] (NoArg (Annex.setFlag "all"))
"operate on all versions of all files"
, Option ['U'] ["unused"] (NoArg (Annex.setFlag "unused"))
"operate on files found by last run of git-annex unused"
, Option [] ["key"] (ReqArg (Annex.setField "key") paramKey)
"operate on specified key"
]
fromOption :: Option
2014-01-26 20:25:55 +00:00
fromOption = fieldOption ['f'] "from" paramRemote "source remote"
toOption :: Option
2014-01-26 20:25:55 +00:00
toOption = fieldOption ['t'] "to" paramRemote "destination remote"
fromToOptions :: [Option]
fromToOptions = [fromOption, toOption]
jsonOption :: Option
jsonOption = Option ['j'] ["json"] (NoArg (Annex.setOutput JSONOutput))
"enable JSON output"