The file matching options are now only accepted by commands that can actually use them.
This commit is contained in:
parent
52424dc382
commit
8066a1c3cc
24 changed files with 118 additions and 77 deletions
|
@ -1,6 +1,6 @@
|
|||
{- git-annex options
|
||||
-
|
||||
- Copyright 2010, 2013 Joey Hess <id@joeyh.name>
|
||||
- Copyright 2010-2015 Joey Hess <id@joeyh.name>
|
||||
-
|
||||
- Licensed under the GNU GPL version 3 or higher.
|
||||
-}
|
||||
|
@ -22,6 +22,8 @@ import qualified Limit.Wanted
|
|||
import CmdLine.Option
|
||||
import CmdLine.Usage
|
||||
|
||||
-- Options that are accepted by all git-annex sub-commands,
|
||||
-- although not always used.
|
||||
gitAnnexOptions :: [Option]
|
||||
gitAnnexOptions = commonOptions ++
|
||||
[ Option ['N'] ["numcopies"] (ReqArg setnumcopies paramNumber)
|
||||
|
@ -34,11 +36,48 @@ gitAnnexOptions = commonOptions ++
|
|||
"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"
|
||||
, Option ['i'] ["in"] (ReqArg Limit.addIn paramRemote)
|
||||
, Option [] ["user-agent"] (ReqArg setuseragent paramName)
|
||||
"override default User-Agent"
|
||||
, Option [] ["trust-glacier"] (NoArg (Annex.setFlag "trustglacier"))
|
||||
"Trust Amazon Glacier inventory"
|
||||
]
|
||||
where
|
||||
trustArg t = ReqArg (Remote.forceTrust t) paramRemote
|
||||
setnumcopies v = maybe noop
|
||||
(\n -> Annex.changeState $ \s -> s { Annex.forcenumcopies = Just $ NumCopies n })
|
||||
(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
|
||||
|
||||
-- Options for matching on annexed keys, rather than work tree files.
|
||||
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"
|
||||
]
|
||||
|
||||
-- Options to match properties of annexed files.
|
||||
annexedMatchingOptions :: [Option]
|
||||
annexedMatchingOptions = concat
|
||||
[ nonWorkTreeMatchingOptions'
|
||||
, fileMatchingOptions'
|
||||
, combiningOptions
|
||||
, [timeLimitOption]
|
||||
]
|
||||
|
||||
-- Matching options that don't need to examine work tree files.
|
||||
nonWorkTreeMatchingOptions :: [Option]
|
||||
nonWorkTreeMatchingOptions = nonWorkTreeMatchingOptions' ++ combiningOptions
|
||||
|
||||
nonWorkTreeMatchingOptions' :: [Option]
|
||||
nonWorkTreeMatchingOptions' =
|
||||
[ Option ['i'] ["in"] (ReqArg Limit.addIn paramRemote)
|
||||
"match files present in a remote"
|
||||
, Option ['C'] ["copies"] (ReqArg Limit.addCopies paramNumber)
|
||||
"skip files with fewer copies"
|
||||
|
@ -50,43 +89,42 @@ gitAnnexOptions = commonOptions ++
|
|||
"match files using a key-value backend"
|
||||
, Option [] ["inallgroup"] (ReqArg Limit.addInAllGroup paramGroup)
|
||||
"match files present in all remotes in a group"
|
||||
, Option [] ["largerthan"] (ReqArg Limit.addLargerThan paramSize)
|
||||
"match files larger than a size"
|
||||
, 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)
|
||||
"match files the repository wants to get"
|
||||
, Option [] ["want-drop"] (NoArg Limit.Wanted.addWantDrop)
|
||||
"match files the repository wants to drop"
|
||||
, 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"
|
||||
, Option [] ["trust-glacier"] (NoArg (Annex.setFlag "trustglacier"))
|
||||
"Trust Amazon Glacier inventory"
|
||||
] ++ matcherOptions
|
||||
where
|
||||
trustArg t = ReqArg (Remote.forceTrust t) paramRemote
|
||||
setnumcopies v = maybe noop
|
||||
(\n -> Annex.changeState $ \s -> s { Annex.forcenumcopies = Just $ NumCopies n })
|
||||
(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"
|
||||
]
|
||||
|
||||
-- Options to match files which may not yet be annexed.
|
||||
fileMatchingOptions :: [Option]
|
||||
fileMatchingOptions = fileMatchingOptions' ++ combiningOptions
|
||||
|
||||
fileMatchingOptions' :: [Option]
|
||||
fileMatchingOptions' =
|
||||
[ 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"
|
||||
, Option [] ["largerthan"] (ReqArg Limit.addLargerThan paramSize)
|
||||
"match files larger than a size"
|
||||
, Option [] ["smallerthan"] (ReqArg Limit.addSmallerThan paramSize)
|
||||
"match files smaller than a size"
|
||||
]
|
||||
|
||||
combiningOptions :: [Option]
|
||||
combiningOptions =
|
||||
[ longopt "not" "negate next option"
|
||||
, longopt "and" "both previous and next option must match"
|
||||
, longopt "or" "either previous or next option must match"
|
||||
, shortopt "(" "open group of options"
|
||||
, shortopt ")" "close group of options"
|
||||
]
|
||||
where
|
||||
longopt o = Option [] [o] $ NoArg $ Limit.addToken o
|
||||
shortopt o = Option o [] $ NoArg $ Limit.addToken o
|
||||
|
||||
fromOption :: Option
|
||||
fromOption = fieldOption ['f'] "from" paramRemote "source remote"
|
||||
|
||||
|
@ -99,3 +137,8 @@ fromToOptions = [fromOption, toOption]
|
|||
jsonOption :: Option
|
||||
jsonOption = Option ['j'] ["json"] (NoArg (Annex.setOutput JSONOutput))
|
||||
"enable JSON output"
|
||||
|
||||
timeLimitOption :: Option
|
||||
timeLimitOption = Option ['T'] ["time-limit"]
|
||||
(ReqArg Limit.addTimeLimit paramTime)
|
||||
"stop after the specified amount of time"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue