diff --git a/CmdLine/Usage.hs b/CmdLine/Usage.hs index 64b512144d..1d0bba9543 100644 --- a/CmdLine/Usage.hs +++ b/CmdLine/Usage.hs @@ -73,6 +73,8 @@ paramNumRange :: String paramNumRange = "NUM|RANGE" paramRemote :: String paramRemote = "REMOTE" +paramField :: String +paramField = "FIELD" paramGlob :: String paramGlob = "GLOB" paramName :: String diff --git a/Command/MetaData.hs b/Command/MetaData.hs index 55d67c6b77..d49c8429d3 100644 --- a/Command/MetaData.hs +++ b/Command/MetaData.hs @@ -18,7 +18,7 @@ import qualified Data.Set as S import Data.Time.Clock.POSIX def :: [Command] -def = [withOptions [setOption, tagOption, untagOption, jsonOption] $ +def = [withOptions [setOption, tagOption, untagOption, getOption, jsonOption] $ command "metadata" paramPaths seek SectionMetaData "sets metadata of a file"] @@ -31,6 +31,9 @@ setOption = Option ['s'] ["set"] (ReqArg mkmod "FIELD[+-]=VALUE") "set metadata" where mkmod = either error storeModMeta . parseModMeta +getOption :: Option +getOption = fieldOption ['g'] "get" paramField "get single metadata field" + tagOption :: Option tagOption = Option ['t'] ["tag"] (ReqArg mkmod "TAG") "set a tag" where @@ -44,13 +47,20 @@ untagOption = Option ['u'] ["untag"] (ReqArg mkmod "TAG") "remove a tag" seek :: CommandSeek seek ps = do modmeta <- Annex.getState Annex.modmeta + getfield <- getOptionField getOption $ \ms -> + return $ either error id . mkMetaField <$> ms now <- liftIO getPOSIXTime - withFilesInGit (whenAnnexed $ start now modmeta) ps + withFilesInGit (whenAnnexed $ start now getfield modmeta) ps -start :: POSIXTime -> [ModMeta] -> FilePath -> (Key, Backend) -> CommandStart -start now ms file (k, _) = do +start :: POSIXTime -> Maybe MetaField -> [ModMeta] -> FilePath -> (Key, Backend) -> CommandStart +start now Nothing ms file (k, _) = do showStart "metadata" file next $ perform now ms k +start _ (Just f) _ _ (k, _) = do + l <- S.toList . currentMetaDataValues f <$> getCurrentMetaData k + liftIO $ forM_ l $ + putStrLn . fromMetaValue + stop perform :: POSIXTime -> [ModMeta] -> Key -> CommandPerform perform _ [] k = next $ cleanup k diff --git a/debian/changelog b/debian/changelog index 6c17254297..56cfe88e08 100644 --- a/debian/changelog +++ b/debian/changelog @@ -22,6 +22,7 @@ git-annex (5.20140307) UNRELEASED; urgency=medium * Avoid encoding errors when using the unused log file. * vicfg: Allows editing preferred content expressions for groups. * groupwanted can be used in preferred content expressions. + * metadata: Add --get -- Joey Hess Thu, 06 Mar 2014 16:17:01 -0400 diff --git a/doc/git-annex.mdwn b/doc/git-annex.mdwn index e73c08ca25..32c8ec2662 100644 --- a/doc/git-annex.mdwn +++ b/doc/git-annex.mdwn @@ -705,12 +705,20 @@ subdirectories). # METADATA COMMANDS -* `metadata [path ...] [-s field=value -s field+=value -s field-=value ...]` +* `metadata [path ...] [-s field=value -s field+=value -s field-=value ...] [-g field]` Each file can have any number of metadata fields attached to it, - which each in turn have any number of values. This sets metadata - for the specified file or files, or if run without any values, shows - the current metadata. + which each in turn have any number of values. + + This command can be used to set metadata, or show the currently set + metadata. + + To show current metadata, run without any -s parameters. The --json + option will enable json output. + + To only get the value(s) of a single field, use -g field. + The values will be output one per line, with no other output, so + this is suitable for use in a script. To set a field's value, removing any old value(s), use -s field=value.