metadata: Add --get (from bremner)

This commit is contained in:
Joey Hess 2014-03-15 17:29:40 -04:00
parent 34c6720bdf
commit 8bcd67b9d8
4 changed files with 29 additions and 8 deletions

View file

@ -73,6 +73,8 @@ paramNumRange :: String
paramNumRange = "NUM|RANGE"
paramRemote :: String
paramRemote = "REMOTE"
paramField :: String
paramField = "FIELD"
paramGlob :: String
paramGlob = "GLOB"
paramName :: String

View file

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

1
debian/changelog vendored
View file

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

View file

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