1
0
mirror of synced 2026-06-26 21:50:48 +00:00

Simplify status filter in get command

Signed-off-by: Matheus Pimenta <matheuscscp@gmail.com>
This commit is contained in:
Matheus Pimenta
2026-06-25 08:27:45 +01:00
parent 5afd1d8728
commit f234f2f26f
+10 -14
View File
@@ -228,16 +228,20 @@ func namespaceNameOrAny(allNamespaces bool, namespaceName string) string {
}
func getRowsToPrint(getAll bool, list summarisable) ([][]string, error) {
noFilter := true
filter := func(i int) bool { return true }
var conditionType, conditionStatus string
var negate bool
if getArgs.statusSelector != "" {
// Support both type=status (match) and type!=status (negated match).
// "!=" must be checked first since it also contains "=".
separator := "="
filter = func(i int) bool {
return list.statusSelectorMatches(i, conditionType, conditionStatus)
}
if strings.Contains(getArgs.statusSelector, "!=") {
separator = "!="
negate = true
filter = func(i int) bool {
return !list.statusSelectorMatches(i, conditionType, conditionStatus)
}
}
parts := strings.SplitN(getArgs.statusSelector, separator, 2)
if len(parts) != 2 {
@@ -245,21 +249,13 @@ func getRowsToPrint(getAll bool, list summarisable) ([][]string, error) {
}
conditionType = parts[0]
conditionStatus = parts[1]
noFilter = false
}
var rows [][]string
for i := 0; i < list.len(); i++ {
if !noFilter {
matches := list.statusSelectorMatches(i, conditionType, conditionStatus)
if negate {
matches = !matches
}
if !matches {
continue
}
if filter(i) {
row := list.summariseItem(i, getArgs.allNamespaces, getAll)
rows = append(rows, row)
}
row := list.summariseItem(i, getArgs.allNamespaces, getAll)
rows = append(rows, row)
}
return rows, nil
}