-
Notifications
You must be signed in to change notification settings - Fork 1
/
local_tag.go
79 lines (64 loc) · 1.66 KB
/
local_tag.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package vangogh_local_data
import (
"github.com/boggydigital/kevlar"
"github.com/boggydigital/nod"
)
func addLocalTag(id, tag string, rdx kevlar.WriteableRedux, tpw nod.TotalProgressWriter) error {
if err := rdx.MustHave(LocalTagsProperty); err != nil {
return err
}
if !rdx.HasValue(LocalTagsProperty, id, tag) {
if err := rdx.AddValues(LocalTagsProperty, id, tag); err != nil {
nod.Increment(tpw)
return err
}
}
nod.Increment(tpw)
return nil
}
func removeLocalTag(id, tag string, rdx kevlar.WriteableRedux, tpw nod.TotalProgressWriter) error {
if err := rdx.MustHave(LocalTagsProperty); err != nil {
return err
}
if rdx.HasValue(LocalTagsProperty, id, tag) {
if err := rdx.CutValues(LocalTagsProperty, id, tag); err != nil {
nod.Increment(tpw)
return err
}
}
nod.Increment(tpw)
return nil
}
func AddLocalTags(ids, tags []string, tpw nod.TotalProgressWriter) error {
rxa, err := NewReduxWriter(LocalTagsProperty)
if err != nil {
return err
}
nod.TotalInt(tpw, len(ids)*len(tags))
for _, id := range ids {
for _, tag := range tags {
if err := addLocalTag(id, tag, rxa, tpw); err != nil {
return err
}
}
}
return nil
}
func RemoveLocalTags(ids, tags []string, tpw nod.TotalProgressWriter) error {
rxa, err := NewReduxWriter(LocalTagsProperty)
if err != nil {
return err
}
nod.TotalInt(tpw, len(ids)*len(tags))
for _, id := range ids {
for _, tag := range tags {
if err := removeLocalTag(id, tag, rxa, tpw); err != nil {
return err
}
}
}
return nil
}
func DiffLocalTags(id string, newTags []string) (add []string, rem []string, err error) {
return diffTagProperty(LocalTagsProperty, id, newTags)
}