Skip to content

Commit

Permalink
tags: change --tagged require all tags
Browse files Browse the repository at this point in the history
  • Loading branch information
adamtulinius committed Sep 8, 2020
1 parent 48761e6 commit 32b321b
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions filter/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,33 @@ func FilterHosts(allHosts []nix.Host, skip int, every int, limit int) (hosts []n
}
}

func hasTag(host nix.Host, tag string) bool {
for _, hostTag := range host.GetTags() {
if hostTag == tag {
return true
}
}

return false
}

func FilterHostsTags(allHosts []nix.Host, selectedTags []string) (hosts []nix.Host) {
if len(selectedTags) == 0 {
return allHosts
}

for _, host := range allHosts {
for _, tag := range host.GetTags() {
for _, selectTag := range selectedTags {
if tag == selectTag {
hosts = append(hosts, host)
break
}
include := true
for _, selectTag := range selectedTags {
if !hasTag(host, selectTag) {
include = false;
break
}

}

if include {
hosts = append(hosts, host)
}
}

Expand Down

0 comments on commit 32b321b

Please sign in to comment.