Skip to content

Commit 26376e8

Browse files
authored
Merge pull request kubernetes-sigs#6873 from oscr/clusterctl-error-msg
🌱 Improve clusterctl completion and get kubeconfig error message
2 parents 26943ea + 93e4183 commit 26376e8

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

cmd/clusterctl/cmd/completion.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"io"
2323
"os"
2424

25+
"github.com/pkg/errors"
2526
"github.com/spf13/cobra"
2627
"github.com/spf13/pflag"
2728
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -82,7 +83,12 @@ var (
8283
Short: "Output shell completion code for the specified shell (bash or zsh)",
8384
Long: LongDesc(completionLong),
8485
Example: completionExample,
85-
Args: cobra.ExactArgs(1),
86+
Args: func(cmd *cobra.Command, args []string) error {
87+
if len(args) != 1 {
88+
return errors.New("please specify a shell")
89+
}
90+
return nil
91+
},
8692
RunE: func(cmd *cobra.Command, args []string) error {
8793
return runCompletion(os.Stdout, cmd, args[0])
8894
},

cmd/clusterctl/cmd/get_kubeconfig.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package cmd
1919
import (
2020
"fmt"
2121

22+
"github.com/pkg/errors"
2223
"github.com/spf13/cobra"
2324

2425
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
@@ -46,7 +47,12 @@ var getKubeconfigCmd = &cobra.Command{
4647
# Get the workload cluster's kubeconfig in a particular namespace.
4748
clusterctl get kubeconfig <name of workload cluster> --namespace foo`),
4849

49-
Args: cobra.ExactArgs(1),
50+
Args: func(cmd *cobra.Command, args []string) error {
51+
if len(args) != 1 {
52+
return errors.New("please specify a workload cluster name")
53+
}
54+
return nil
55+
},
5056
RunE: func(cmd *cobra.Command, args []string) error {
5157
return runGetKubeconfig(args[0])
5258
},

0 commit comments

Comments
 (0)