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