From 2b04d6d9bdb7f1382a7bac770968fe3be21f6a94 Mon Sep 17 00:00:00 2001 From: iyear Date: Thu, 13 Apr 2023 18:40:18 +0800 Subject: [PATCH 1/2] feat: delete cluster flag completion --- pkg/cmd/kind/delete/cluster/deletecluster.go | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/pkg/cmd/kind/delete/cluster/deletecluster.go b/pkg/cmd/kind/delete/cluster/deletecluster.go index 3fa98c5be0..f3ab5b0bdc 100644 --- a/pkg/cmd/kind/delete/cluster/deletecluster.go +++ b/pkg/cmd/kind/delete/cluster/deletecluster.go @@ -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", @@ -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 } From aff690db637db85dea9eafd9c385e60b7ad0dfc5 Mon Sep 17 00:00:00 2001 From: iyear Date: Thu, 25 May 2023 14:35:25 +0800 Subject: [PATCH 2/2] chore: remove name flag constant --- pkg/cmd/kind/delete/cluster/deletecluster.go | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/pkg/cmd/kind/delete/cluster/deletecluster.go b/pkg/cmd/kind/delete/cluster/deletecluster.go index f3ab5b0bdc..05e5059a7f 100644 --- a/pkg/cmd/kind/delete/cluster/deletecluster.go +++ b/pkg/cmd/kind/delete/cluster/deletecluster.go @@ -49,13 +49,9 @@ func NewCommand(logger log.Logger, streams cmd.IOStreams) *cobra.Command { }, } - const ( - nameFlag = "name" - ) - cmd.Flags().StringVarP( &flags.Name, - nameFlag, + "name", "n", cluster.DefaultName, "the cluster name", @@ -67,7 +63,7 @@ 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) { + cobra.CheckErr(cmd.RegisterFlagCompletionFunc("name", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { clusters, err := cluster.NewProvider( cluster.ProviderWithLogger(logger), runtime.GetDefault(logger),