metadata: Added -r to remove all current values of a field.

This commit is contained in:
Joey Hess 2016-02-29 13:00:46 -04:00
parent 98fcc23e4f
commit e520366c4d
Failed to extract signature
5 changed files with 39 additions and 17 deletions

View file

@ -61,7 +61,7 @@ dateMetaData mtime old = MetaData $ M.fromList $ filter isnew
parseModMeta :: String -> Either String ModMeta parseModMeta :: String -> Either String ModMeta
parseModMeta p = case lastMaybe f of parseModMeta p = case lastMaybe f of
Just '+' -> AddMeta <$> mkMetaField f' <*> v Just '+' -> AddMeta <$> mkMetaField f' <*> v
Just '-' -> DelMeta <$> mkMetaField f' <*> v Just '-' -> DelMeta <$> mkMetaField f' <*> (Just <$> v)
Just '?' -> MaybeSetMeta <$> mkMetaField f' <*> v Just '?' -> MaybeSetMeta <$> mkMetaField f' <*> v
_ -> SetMeta <$> mkMetaField f <*> v _ -> SetMeta <$> mkMetaField f <*> v
where where

View file

@ -46,10 +46,14 @@ optParser desc = MetaDataOptions
( long "tag" <> short 't' <> metavar "TAG" ( long "tag" <> short 't' <> metavar "TAG"
<> help "set a tag" <> help "set a tag"
)) ))
<|> (DelMeta tagMetaField . toMetaValue <$> strOption <|> (DelMeta tagMetaField . Just . toMetaValue <$> strOption
( long "untag" <> short 'u' <> metavar "TAG" ( long "untag" <> short 'u' <> metavar "TAG"
<> help "remove a tag" <> help "remove a tag"
)) ))
<|> option (eitherReader (\f -> DelMeta <$> mkMetaField f <*> pure Nothing))
( long "remove" <> short 'r' <> metavar "FIELD"
<> help "remove all values of a field"
)
seek :: MetaDataOptions -> CommandSeek seek :: MetaDataOptions -> CommandSeek
seek o = do seek o = do

View file

@ -219,9 +219,13 @@ metaDataValues f (MetaData m) = fromMaybe S.empty (M.lookup f m)
{- Ways that existing metadata can be modified -} {- Ways that existing metadata can be modified -}
data ModMeta data ModMeta
= AddMeta MetaField MetaValue = AddMeta MetaField MetaValue
| DelMeta MetaField MetaValue | DelMeta MetaField (Maybe MetaValue)
| SetMeta MetaField MetaValue -- removes any existing values -- ^ delete value of a field. With Just, only that specific value
| MaybeSetMeta MetaField MetaValue -- when field has no existing value -- is deleted; with Nothing, all current values are deleted.
| SetMeta MetaField MetaValue
-- ^ removes any existing values
| MaybeSetMeta MetaField MetaValue
-- ^ set when field has no existing value
deriving (Show) deriving (Show)
{- Applies a ModMeta, generating the new MetaData. {- Applies a ModMeta, generating the new MetaData.
@ -229,7 +233,10 @@ data ModMeta
- values set in the input metadata. It only contains changed values. -} - values set in the input metadata. It only contains changed values. -}
modMeta :: MetaData -> ModMeta -> MetaData modMeta :: MetaData -> ModMeta -> MetaData
modMeta _ (AddMeta f v) = updateMetaData f v emptyMetaData modMeta _ (AddMeta f v) = updateMetaData f v emptyMetaData
modMeta _ (DelMeta f oldv) = updateMetaData f (unsetMetaValue oldv) emptyMetaData modMeta _ (DelMeta f (Just oldv)) =
updateMetaData f (unsetMetaValue oldv) emptyMetaData
modMeta m (DelMeta f Nothing) = MetaData $ M.singleton f $
S.fromList $ map unsetMetaValue $ S.toList $ currentMetaDataValues f m
modMeta m (SetMeta f v) = updateMetaData f v $ modMeta m (SetMeta f v) = updateMetaData f v $
foldr (updateMetaData f) emptyMetaData $ foldr (updateMetaData f) emptyMetaData $
map unsetMetaValue $ S.toList $ currentMetaDataValues f m map unsetMetaValue $ S.toList $ currentMetaDataValues f m

6
debian/changelog vendored
View file

@ -1,3 +1,9 @@
git-annex (6.20160230) UNRELEASED; urgency=medium
* metadata: Added -r to remove all current values of a field.
-- Joey Hess <id@joeyh.name> Mon, 29 Feb 2016 13:00:30 -0400
git-annex (6.20160229) unstable; urgency=medium git-annex (6.20160229) unstable; urgency=medium
* Update perlmagick build dependency. Closes: #789225 * Update perlmagick build dependency. Closes: #789225

View file

@ -19,34 +19,39 @@ When run without any -s or -t parameters, displays the current metadata.
# OPTIONS # OPTIONS
* `-g field` * `-g field` / `--get field`
Get the value(s) of a single field. Get the value(s) of a single field.
The values will be output one per line, with no other output, so The values will be output one per line, with no other output, so
this is suitable for use in a script. this is suitable for use in a script.
* `-s field=value` * `-s field=value` / `--set field=value`
Set a field's value, removing any old values. Set a field's value, removing any old values.
* `-s field+=value` * `-s field+=value` / `--set field+=value`
Add an additional value, preserving any old values. Add an additional value, preserving any old values.
* `-s field-=value` * `-s field?=value` / `--set field?=value`
Remove a value.
* `-s field?=value`
Set a value, but only if the field does not already have a value set. Set a value, but only if the field does not already have a value set.
* `-t tag` * `-s field-=value` / `--set field-=value`
Remove a value from a field, leaving any other values that the field has
set.
* `-r field` / `--remove field`
Remove all current values of the field.
* `-t tag` / `--tag tag`
Set a tag. Note that a tag is just a value of the "tag" field. Set a tag. Note that a tag is just a value of the "tag" field.
* `-u tag` * `-u tag` / `--unset tag`
Unset a tag. Unset a tag.