support filter by many same options

This commit is contained in:
Arnas Udovicius 2022-08-30 19:39:40 +03:00
parent 7ed3c128f4
commit 6bc45afab5

22
tree.go
View file

@ -60,24 +60,26 @@ func (t Tree) Slice(path string) (Tree, error) {
return Tree{}, errors.New("tree was not found") return Tree{}, errors.New("tree was not found")
} }
func (t Tree) Filter(filter map[string]string) (Tree, bool) { func (t Tree) Filter(filter map[string][]string) (Tree, bool) {
filtered := Tree{} filtered := Tree{}
filtered.Path = t.Path filtered.Path = t.Path
found := false found := false
for _, f := range t.Files { for _, f := range t.Files {
addFile := false addFile := false
for option, value := range filter { for option, values := range filter {
if option == "tag" { for _, value := range values {
for _, tag := range f.Tags { if option == "tag" {
if tag == value { for _, tag := range f.Tags {
addFile = true if tag == value {
addFile = true
}
} }
continue
}
if strings.Contains(f.Meta[option], value) {
addFile = true
} }
continue
}
if strings.Contains(f.Meta[option], value) {
addFile = true
} }
} }
if addFile { if addFile {