diff options
author | Joey Hess <joey@kitenet.net> | 2014-03-15 17:29:40 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2014-03-15 17:29:40 -0400 |
commit | 19acc4def407d16f8719169cc15c89b9d0498cd6 (patch) | |
tree | 9e5faae5ee87df2c366ec859b6f41fd33820876a | |
parent | a6a8c898025a1a3dba2a06620270455e30034313 (diff) |
metadata: Add --get (from bremner)
-rw-r--r-- | CmdLine/Usage.hs | 2 | ||||
-rw-r--r-- | Command/MetaData.hs | 18 | ||||
-rw-r--r-- | debian/changelog | 1 | ||||
-rw-r--r-- | doc/git-annex.mdwn | 16 |
4 files changed, 29 insertions, 8 deletions
diff --git a/CmdLine/Usage.hs b/CmdLine/Usage.hs index 64b512144..1d0bba954 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 55d67c6b7..d49c8429d 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 6c1725429..56cfe88e0 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 <joeyh@debian.org> Thu, 06 Mar 2014 16:17:01 -0400 diff --git a/doc/git-annex.mdwn b/doc/git-annex.mdwn index e73c08ca2..32c8ec266 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. |