Skip to content

Commit

Permalink
feat: delete cluster flag completion
Browse files Browse the repository at this point in the history
  • Loading branch information
iyear committed Apr 18, 2023
1 parent 822f496 commit 2b04d6d
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion pkg/cmd/kind/delete/cluster/deletecluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,14 @@ func NewCommand(logger log.Logger, streams cmd.IOStreams) *cobra.Command {
return deleteCluster(logger, flags)
},
}

const (
nameFlag = "name"
)

cmd.Flags().StringVarP(
&flags.Name,
"name",
nameFlag,
"n",
cluster.DefaultName,
"the cluster name",
Expand All @@ -61,6 +66,19 @@ func NewCommand(logger log.Logger, streams cmd.IOStreams) *cobra.Command {
"",
"sets kubeconfig path instead of $KUBECONFIG or $HOME/.kube/config",
)

cobra.CheckErr(cmd.RegisterFlagCompletionFunc(nameFlag, func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
clusters, err := cluster.NewProvider(
cluster.ProviderWithLogger(logger),
runtime.GetDefault(logger),
).List()
if err != nil {
return nil, cobra.ShellCompDirectiveError
}

return clusters, cobra.ShellCompDirectiveNoFileComp
}))

return cmd
}

Expand Down

0 comments on commit 2b04d6d

Please sign in to comment.