The file matching options are now only accepted by commands that can actually use them.

This commit is contained in:
Joey Hess 2015-02-06 17:08:14 -04:00
parent 52424dc382
commit 8066a1c3cc
24 changed files with 118 additions and 77 deletions

View file

@ -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"

View file

@ -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 =

View file

@ -55,7 +55,7 @@ noRepo a c = c { cmdnorepo = Just a }
{- Adds options to a command. -}
withOptions :: [Option] -> Command -> Command
withOptions o c = c { cmdoptions = o }
withOptions o c = c { cmdoptions = cmdoptions c ++ o }
{- For start and perform stages to indicate what step to run next. -}
next :: a -> Annex (Maybe a)

View file

@ -35,9 +35,11 @@ import Utility.Tmp
import Control.Exception (IOException)
cmd :: [Command]
cmd = [notBareRepo $ withOptions [includeDotFilesOption] $
command "add" paramPaths seek SectionCommon
"add files to annex"]
cmd = [notBareRepo $ withOptions addOptions $
command "add" paramPaths seek SectionCommon "add files to annex"]
addOptions :: [Option]
addOptions = includeDotFilesOption : fileMatchingOptions
includeDotFilesOption :: Option
includeDotFilesOption = flagOption [] "include-dotfiles" "don't skip dotfiles"

View file

@ -23,9 +23,12 @@ import Annex.Notification
import qualified Data.Set as S
cmd :: [Command]
cmd = [withOptions [dropFromOption] $ command "drop" paramPaths seek
cmd = [withOptions (dropOptions) $ command "drop" paramPaths seek
SectionCommon "indicate content of files not currently wanted"]
dropOptions :: [Option]
dropOptions = dropFromOption : annexedMatchingOptions
dropFromOption :: Option
dropFromOption = fieldOption ['f'] "from" paramRemote "drop content from a remote"

View file

@ -20,7 +20,8 @@ import Utility.DataUnits
import Types.Key
cmd :: [Command]
cmd = [mkCommand $ command "find" paramPaths seek SectionQuery "lists available files"]
cmd = [withOptions annexedMatchingOptions $ mkCommand $
command "find" paramPaths seek SectionQuery "lists available files"]
mkCommand :: Command -> Command
mkCommand = noCommit . noMessages . withOptions [formatOption, print0Option, jsonOption]

View file

@ -11,8 +11,9 @@ import Command
import qualified Command.Find as Find
cmd :: [Command]
cmd = [Find.mkCommand $ command "findref" paramRef seek SectionPlumbing
"lists files in a git ref"]
cmd = [withOptions nonWorkTreeMatchingOptions $ Find.mkCommand $
command "findref" paramRef seek SectionPlumbing
"lists files in a git ref"]
seek :: CommandSeek
seek refs = do

View file

@ -19,8 +19,9 @@ import Utility.Touch
#endif
cmd :: [Command]
cmd = [notDirect $ noCommit $ command "fix" paramPaths seek
SectionMaintenance "fix up symlinks to point to annexed content"]
cmd = [notDirect $ noCommit $ withOptions annexedMatchingOptions $
command "fix" paramPaths seek
SectionMaintenance "fix up symlinks to point to annexed content"]
seek :: CommandSeek
seek = withFilesInGit $ whenAnnexed start

View file

@ -62,7 +62,7 @@ fsckOptions =
, startIncrementalOption
, moreIncrementalOption
, incrementalScheduleOption
] ++ keyOptions
] ++ keyOptions ++ annexedMatchingOptions
seek :: CommandSeek
seek ps = do

View file

@ -21,7 +21,7 @@ cmd = [withOptions getOptions $ command "get" paramPaths seek
SectionCommon "make content of annexed files available"]
getOptions :: [Option]
getOptions = fromOption : keyOptions
getOptions = fromOption : annexedMatchingOptions ++ keyOptions
seek :: CommandSeek
seek ps = do

View file

@ -26,7 +26,7 @@ opts =
, deduplicateOption
, cleanDuplicatesOption
, skipDuplicatesOption
]
] ++ fileMatchingOptions
duplicateOption :: Option
duplicateOption = flagOption [] "duplicate" "do not delete source files"

View file

@ -77,7 +77,7 @@ emptyStatInfo = StatInfo Nothing Nothing M.empty Nothing
type StatState = StateT StatInfo Annex
cmd :: [Command]
cmd = [noCommit $ dontCheck repoExists $ withOptions [jsonOption] $
cmd = [noCommit $ dontCheck repoExists $ withOptions (jsonOption : annexedMatchingOptions) $
command "info" (paramOptional $ paramRepeating paramItem) seek SectionQuery
"shows information about the specified item or the repository as a whole"]

View file

@ -24,8 +24,9 @@ import qualified Annex
import Git.Types (RemoteName)
cmd :: [Command]
cmd = [noCommit $ withOptions [allrepos] $ command "list" paramPaths seek
SectionQuery "show which remotes contain files"]
cmd = [noCommit $ withOptions (allrepos : annexedMatchingOptions) $
command "list" paramPaths seek
SectionQuery "show which remotes contain files"]
allrepos :: Option
allrepos = flagOption [] "allrepos" "show all repositories, not only remotes"

View file

@ -13,7 +13,8 @@ import qualified Annex.Queue
import qualified Annex
cmd :: [Command]
cmd = [notDirect $ command "lock" paramPaths seek SectionCommon
cmd = [notDirect $ withOptions annexedMatchingOptions $
command "lock" paramPaths seek SectionCommon
"undo unlock command"]
seek :: CommandSeek

View file

@ -39,7 +39,7 @@ cmd = [withOptions options $
command "log" paramPaths seek SectionQuery "shows location log"]
options :: [Option]
options = passthruOptions ++ [gourceOption]
options = passthruOptions ++ [gourceOption] ++ annexedMatchingOptions
passthruOptions :: [Option]
passthruOptions = map odate ["since", "after", "until", "before"] ++

View file

@ -28,7 +28,7 @@ metaDataOptions =
, untagOption
, getOption
, jsonOption
] ++ keyOptions
] ++ keyOptions ++ annexedMatchingOptions
storeModMeta :: ModMeta -> Annex ()
storeModMeta modmeta = Annex.changeState $

View file

@ -18,7 +18,7 @@ import qualified Command.ReKey
import qualified Command.Fsck
cmd :: [Command]
cmd = [notDirect $
cmd = [notDirect $ withOptions annexedMatchingOptions $
command "migrate" paramPaths seek
SectionUtility "switch data to different backend"]

View file

@ -18,7 +18,7 @@ import qualified Annex
import Config.NumCopies
cmd :: [Command]
cmd = [withOptions (fromToOptions ++ keyOptions) $
cmd = [withOptions (fromToOptions ++ annexedMatchingOptions ++ keyOptions) $
command "mirror" paramPaths seek
SectionCommon "mirror content of files to/from another repository"]

View file

@ -22,7 +22,7 @@ cmd = [withOptions moveOptions $ command "move" paramPaths seek
SectionCommon "move content of files to/from another repository"]
moveOptions :: [Option]
moveOptions = fromToOptions ++ keyOptions
moveOptions = fromToOptions ++ keyOptions ++ annexedMatchingOptions
seek :: CommandSeek
seek ps = do

View file

@ -23,7 +23,8 @@ import Utility.CopyFile
import Command.PreCommit (lockPreCommitHook)
cmd :: [Command]
cmd = [command "unannex" paramPaths seek SectionUtility
cmd = [withOptions annexedMatchingOptions $
command "unannex" paramPaths seek SectionUtility
"undo accidential add command"]
seek :: CommandSeek

View file

@ -19,7 +19,8 @@ cmd =
, c "edit" "same as unlock"
]
where
c n = notDirect . command n paramPaths seek SectionCommon
c n = notDirect . withOptions annexedMatchingOptions
. command n paramPaths seek SectionCommon
seek :: CommandSeek
seek = withFilesInGit $ whenAnnexed start

View file

@ -16,7 +16,7 @@ import Logs.Trust
import Logs.Web
cmd :: [Command]
cmd = [noCommit $ withOptions (jsonOption : keyOptions) $
cmd = [noCommit $ withOptions (jsonOption : annexedMatchingOptions ++ keyOptions) $
command "whereis" paramPaths seek SectionQuery
"lists repositories that have file content"]

2
debian/changelog vendored
View file

@ -8,6 +8,8 @@ git-annex (5.20150206) UNRELEASED; urgency=medium
expression.
* import: Support file matching options such as --exclude, --include,
--smallerthan, --largerthan
* The file matching options are now only accepted by commands that
can actually use them, instead of by all commands.
-- Joey Hess <id@joeyh.name> Fri, 06 Feb 2015 13:57:08 -0400

View file

@ -992,9 +992,6 @@ subdirectories).
This is similar to the find command, but instead of finding files in the
current work tree, it finds files in the specified git ref.
Most MATCHING OPTIONS can be used with findref, to limit the files it
finds. However, the --include and --exclude options will not work.
* `proxy -- git cmd [options]`
Only useful in a direct mode repository, this runs the specified git