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 /Command | |
parent | a6a8c898025a1a3dba2a06620270455e30034313 (diff) |
metadata: Add --get (from bremner)
Diffstat (limited to 'Command')
-rw-r--r-- | Command/MetaData.hs | 18 |
1 files changed, 14 insertions, 4 deletions
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 |