diff options
author | Joey Hess <joeyh@joeyh.name> | 2015-02-06 17:08:14 -0400 |
---|---|---|
committer | Joey Hess <joeyh@joeyh.name> | 2015-02-06 17:16:41 -0400 |
commit | 0cb5a870007c8299f8788962bd7dfc0848794dc0 (patch) | |
tree | 43d9d70f436a42f055617df6abdf85972045476b /CmdLine | |
parent | 7d9431ef1b0cff4eece3cd8fc03e429e391d724a (diff) |
The file matching options are now only accepted by commands that can actually use them.
Diffstat (limited to 'CmdLine')
-rw-r--r-- | CmdLine/GitAnnex/Options.hs | 103 | ||||
-rw-r--r-- | CmdLine/Option.hs | 15 |
2 files changed, 74 insertions, 44 deletions
diff --git a/CmdLine/GitAnnex/Options.hs b/CmdLine/GitAnnex/Options.hs index aaa77c92c..add29d8da 100644 --- a/CmdLine/GitAnnex/Options.hs +++ b/CmdLine/GitAnnex/Options.hs @@ -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,39 +36,11 @@ 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) - "match files present in a remote" - , 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)" - , Option ['B'] ["inbackend"] (ReqArg Limit.addInBackend paramName) - "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 @@ -77,6 +51,7 @@ gitAnnexOptions = commonOptions ++ >>= 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")) @@ -87,6 +62,69 @@ keyOptions = "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" + , 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)" + , Option ['B'] ["inbackend"] (ReqArg Limit.addInBackend paramName) + "match files using a key-value backend" + , Option [] ["inallgroup"] (ReqArg Limit.addInAllGroup paramGroup) + "match files present in all remotes in a group" + , 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" + ] + +-- 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" diff --git a/CmdLine/Option.hs b/CmdLine/Option.hs index 1c1331aab..1b82dc83e 100644 --- a/CmdLine/Option.hs +++ b/CmdLine/Option.hs @@ -7,7 +7,6 @@ module CmdLine.Option ( commonOptions, - matcherOptions, flagOption, fieldOption, optionName, @@ -21,9 +20,9 @@ import Common.Annex import qualified Annex import Types.Messages import Types.DesktopNotify -import Limit import CmdLine.Usage +-- Options accepted by both git-annex and git-annex-shell sub-commands. commonOptions :: [Option] commonOptions = [ Option [] ["force"] (NoArg (setforce True)) @@ -56,18 +55,6 @@ commonOptions = unsetdebug = Annex.changeGitConfig $ \c -> c { annexDebug = False } setdesktopnotify v = Annex.changeState $ \s -> s { Annex.desktopnotify = Annex.desktopnotify s <> v } -matcherOptions :: [Option] -matcherOptions = - [ 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 $ addToken o - shortopt o = Option o [] $ NoArg $ addToken o - {- An option that sets a flag. -} flagOption :: String -> String -> String -> Option flagOption short opt description = |