Skip to content

Commit 800037d

Browse files
use pflag.StringSlice for condition-types flag
1 parent 0fd3f63 commit 800037d

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

cmd/kubectl-tree/rootcmd.go

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,17 +88,11 @@ func run(command *cobra.Command, args []string) error {
8888
return errors.Errorf("invalid value for --%s", colorFlag)
8989
}
9090

91-
condTypesArg, err := command.Flags().GetString(conditionTypesFlag)
91+
conditionTypes, err = command.Flags().GetStringSlice(conditionTypesFlag)
9292
if err != nil {
9393
return err
9494
}
95-
if condTypesArg != "" {
96-
conditionTypes = strings.Split(condTypesArg, ",")
97-
// Trim spaces from each condition type
98-
for i := range conditionTypes {
99-
conditionTypes[i] = strings.TrimSpace(conditionTypes[i])
100-
}
101-
} else {
95+
if len(conditionTypes) == 0 {
10296
// Default to "Ready" if not specified
10397
conditionTypes = []string{"Ready"}
10498
}
@@ -199,7 +193,7 @@ func init() {
199193

200194
rootCmd.Flags().BoolP(allNamespacesFlag, "A", false, "query all objects in all API groups, both namespaced and non-namespaced")
201195
rootCmd.Flags().StringP(colorFlag, "c", "auto", "Enable or disable color output. This can be 'always', 'never', or 'auto' (default = use color only if using tty). The flag is overridden by the NO_COLOR env variable if set.")
202-
rootCmd.Flags().String(conditionTypesFlag, "", "Comma-separated list of condition types to check (default: Ready). Example: Ready,Processed,Scheduled")
196+
rootCmd.Flags().StringSlice(conditionTypesFlag, []string{}, "Comma-separated list of condition types to check (default: Ready). Example: Ready,Processed,Scheduled")
203197

204198
cf.AddFlags(rootCmd.Flags())
205199
if err := flag.Set("logtostderr", "true"); err != nil {

0 commit comments

Comments
 (0)