Skip to content
This repository was archived by the owner on Aug 23, 2023. It is now read-only.

Commit 0a21297

Browse files
committed
cleaner filter-skip conditions
1 parent b8f494d commit 0a21297

File tree

1 file changed

+25
-23
lines changed

1 file changed

+25
-23
lines changed

cmd/mt-index-cat/main.go

+25-23
Original file line numberDiff line numberDiff line change
@@ -170,31 +170,33 @@ func main() {
170170
shown := 0
171171

172172
for _, d := range defs {
173-
if prefix == "" || strings.HasPrefix(d.Metric, prefix) {
174-
if substr == "" || strings.Contains(d.Metric, substr) {
175-
if tags != "" {
176-
if tags == "none" && len(d.Tags) != 0 {
177-
continue
178-
}
179-
if tags == "some" && len(d.Tags) == 0 {
180-
continue
181-
}
182-
if tags == "valid" || tags == "invalid" {
183-
valid := schema.ValidateTags(d.Tags)
184-
185-
// skip the metric if the validation result is not what we want
186-
if valid != (tags == "valid") {
187-
continue
188-
}
189-
}
190-
}
191-
show(d)
192-
shown += 1
193-
if shown == limit {
194-
break
195-
}
173+
// note that prefix and substr can be "", meaning filter disabled.
174+
// the conditions handle this fine as well.
175+
if !strings.HasPrefix(d.Metric, prefix) {
176+
continue
177+
}
178+
if !strings.Contains(d.Metric, substr) {
179+
continue
180+
}
181+
if tags == "none" && len(d.Tags) != 0 {
182+
continue
183+
}
184+
if tags == "some" && len(d.Tags) == 0 {
185+
continue
186+
}
187+
if tags == "valid" || tags == "invalid" {
188+
valid := schema.ValidateTags(d.Tags)
189+
190+
// skip the metric if the validation result is not what we want
191+
if valid != (tags == "valid") {
192+
continue
196193
}
197194
}
195+
show(d)
196+
shown += 1
197+
if shown == limit {
198+
break
199+
}
198200
}
199201

200202
if verbose {

0 commit comments

Comments
 (0)