diff --git a/cli/format/format_extended.go b/cli/format/format_extended.go index 543d4e44..3859abac 100644 --- a/cli/format/format_extended.go +++ b/cli/format/format_extended.go @@ -132,14 +132,7 @@ func extendedFormatAnnotations(labels models.LabelSet) string { func extendedFormatMatchers(matchers models.Matchers) string { output := []string{} for _, matcher := range matchers { - output = append(output, extendedFormatMatcher(*matcher)) + output = append(output, simpleFormatMatcher(*matcher)) } return strings.Join(output, " ") } - -func extendedFormatMatcher(matcher models.Matcher) string { - if *matcher.IsRegex { - return fmt.Sprintf("%s=~%s", *matcher.Name, *matcher.Value) - } - return fmt.Sprintf("%s=%s", *matcher.Name, *matcher.Value) -} diff --git a/cli/format/format_simple.go b/cli/format/format_simple.go index 9de64677..9efbb801 100644 --- a/cli/format/format_simple.go +++ b/cli/format/format_simple.go @@ -94,9 +94,17 @@ func simpleFormatMatchers(matchers models.Matchers) string { return strings.Join(output, " ") } -func simpleFormatMatcher(matcher models.Matcher) string { - if *matcher.IsRegex { - return fmt.Sprintf("%s=~%s", *matcher.Name, *matcher.Value) +func simpleFormatMatcher(m models.Matcher) string { + var op string + switch { + case !*m.IsRegex && *m.IsEqual: + op = "=" + case !*m.IsRegex && !*m.IsEqual: + op = "!=" + case *m.IsRegex && *m.IsEqual: + op = "=~" + case *m.IsRegex && !*m.IsEqual: + op = "!~" } - return fmt.Sprintf("%s=%s", *matcher.Name, *matcher.Value) + return fmt.Sprintf("%s%s%q", *m.Name, op, *m.Value) }