diff options
author | Joey Hess <joeyh@joeyh.name> | 2016-02-29 13:00:46 -0400 |
---|---|---|
committer | Joey Hess <joeyh@joeyh.name> | 2016-02-29 13:00:46 -0400 |
commit | 25b87aadd8bdca484f1fb073c38e169ee2bc7503 (patch) | |
tree | a34a85fd37f979ac64f617bef01a1957a0a2b622 /Types | |
parent | 5b23c5d3baa15ca1200b2ee349b924c1d8395665 (diff) |
metadata: Added -r to remove all current values of a field.
Diffstat (limited to 'Types')
-rw-r--r-- | Types/MetaData.hs | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/Types/MetaData.hs b/Types/MetaData.hs index 976f37e46..198fe5d7d 100644 --- a/Types/MetaData.hs +++ b/Types/MetaData.hs @@ -219,9 +219,13 @@ metaDataValues f (MetaData m) = fromMaybe S.empty (M.lookup f m) {- Ways that existing metadata can be modified -} data ModMeta = AddMeta MetaField MetaValue - | DelMeta MetaField MetaValue - | SetMeta MetaField MetaValue -- removes any existing values - | MaybeSetMeta MetaField MetaValue -- when field has no existing value + | DelMeta MetaField (Maybe MetaValue) + -- ^ delete value of a field. With Just, only that specific 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) {- Applies a ModMeta, generating the new MetaData. @@ -229,7 +233,10 @@ data ModMeta - values set in the input metadata. It only contains changed values. -} modMeta :: MetaData -> ModMeta -> MetaData 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 $ foldr (updateMetaData f) emptyMetaData $ map unsetMetaValue $ S.toList $ currentMetaDataValues f m |