metadata: add --tag and --untag shorthand options

This commit is contained in:
Joey Hess 2014-02-19 15:04:12 -04:00
parent e7672f197e
commit d8ce6cac36
2 changed files with 21 additions and 7 deletions

View file

@ -17,16 +17,28 @@ import qualified Data.Set as S
import Data.Time.Clock.POSIX
def :: [Command]
def = [withOptions [setOption] $ command "metadata" paramPaths seek
def = [withOptions [setOption, tagOption, untagOption] $
command "metadata" paramPaths seek
SectionMetaData "sets metadata of a file"]
storeModMeta :: ModMeta -> Annex ()
storeModMeta modmeta = Annex.changeState $
\s -> s { Annex.modmeta = modmeta:Annex.modmeta s }
setOption :: Option
setOption = Option ['s'] ["set"] (ReqArg mkmod "FIELD[+-]=VALUE") "set metadata"
where
mkmod p = case parseModMeta p of
Left e -> error e
Right modmeta -> Annex.changeState $
\s -> s { Annex.modmeta = modmeta:Annex.modmeta s }
mkmod = either error storeModMeta . parseModMeta
tagOption :: Option
tagOption = Option ['t'] ["tag"] (ReqArg mkmod "TAG") "set a tag"
where
mkmod = storeModMeta . AddMeta tagMetaField . toMetaValue
untagOption :: Option
untagOption = Option ['u'] ["untag"] (ReqArg mkmod "TAG") "remove a tag"
where
mkmod = storeModMeta . AddMeta tagMetaField . mkMetaValue (CurrentlySet False)
seek :: CommandSeek
seek ps = do

View file

@ -708,9 +708,11 @@ subdirectories).
To remove a value, use -s field-=value.
For example, to set some tags on a file:
To set a tag, use -t tag, and use -u tag to remove a tag.
git annex metadata annexscreencast.ogv -s tag+=video -s tag+=screencast
For example, to set some tags on a file and also its author:
git annex metadata annexscreencast.ogv -t video -t screencast -s author+=Alice
* `view [field=value ...] [tag ...]`