mirror of https://github.com/k3s-io/k3s
fix kubectl config return 0 on error
parent
302aab9ba2
commit
917a0b6f1b
|
@ -105,11 +105,11 @@ func newCmdConfigSetAuthInfo(out io.Writer, options *createAuthInfoOptions) *cob
|
|||
Long: create_authinfo_long,
|
||||
Example: create_authinfo_example,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if !options.complete(cmd, out) {
|
||||
err := options.complete(cmd, out)
|
||||
if err != nil {
|
||||
cmd.Help()
|
||||
return
|
||||
cmdutil.CheckErr(err)
|
||||
}
|
||||
|
||||
cmdutil.CheckErr(options.run())
|
||||
fmt.Fprintf(out, "User %q set.\n", options.name)
|
||||
},
|
||||
|
@ -238,30 +238,28 @@ func (o *createAuthInfoOptions) modifyAuthInfo(existingAuthInfo clientcmdapi.Aut
|
|||
return modifiedAuthInfo
|
||||
}
|
||||
|
||||
func (o *createAuthInfoOptions) complete(cmd *cobra.Command, out io.Writer) bool {
|
||||
func (o *createAuthInfoOptions) complete(cmd *cobra.Command, out io.Writer) error {
|
||||
args := cmd.Flags().Args()
|
||||
if len(args) != 1 {
|
||||
return false
|
||||
return fmt.Errorf("Unexpected args: %v", args)
|
||||
}
|
||||
|
||||
authProviderArgs, err := cmd.Flags().GetStringSlice(flagAuthProviderArg)
|
||||
if err != nil {
|
||||
fmt.Fprintf(out, "Error: %s\n", err)
|
||||
return false
|
||||
return fmt.Errorf("Error: %s\n", err)
|
||||
}
|
||||
|
||||
if len(authProviderArgs) > 0 {
|
||||
newPairs, removePairs, err := cmdutil.ParsePairs(authProviderArgs, flagAuthProviderArg, true)
|
||||
if err != nil {
|
||||
fmt.Fprintf(out, "Error: %s\n", err)
|
||||
return false
|
||||
return fmt.Errorf("Error: %s\n", err)
|
||||
}
|
||||
o.authProviderArgs = newPairs
|
||||
o.authProviderArgsToRemove = removePairs
|
||||
}
|
||||
|
||||
o.name = args[0]
|
||||
return true
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o createAuthInfoOptions) validate() error {
|
||||
|
|
|
@ -160,7 +160,7 @@ func TestCreateAuthInfoOptions(t *testing.T) {
|
|||
continue
|
||||
}
|
||||
|
||||
if !opts.complete(cmd, buff) {
|
||||
if err := opts.complete(cmd, buff); err != nil {
|
||||
if !test.wantCompleteErr {
|
||||
t.Errorf("case %d: complete() error for flags %q: %s", i, test.flags, buff)
|
||||
}
|
||||
|
|
|
@ -69,10 +69,7 @@ func NewCmdConfigSetCluster(out io.Writer, configAccess clientcmd.ConfigAccess)
|
|||
Long: create_cluster_long,
|
||||
Example: create_cluster_example,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if !options.complete(cmd) {
|
||||
return
|
||||
}
|
||||
|
||||
cmdutil.CheckErr(options.complete(cmd))
|
||||
cmdutil.CheckErr(options.run())
|
||||
fmt.Fprintf(out, "Cluster %q set.\n", options.name)
|
||||
},
|
||||
|
@ -152,15 +149,15 @@ func (o *createClusterOptions) modifyCluster(existingCluster clientcmdapi.Cluste
|
|||
return modifiedCluster
|
||||
}
|
||||
|
||||
func (o *createClusterOptions) complete(cmd *cobra.Command) bool {
|
||||
func (o *createClusterOptions) complete(cmd *cobra.Command) error {
|
||||
args := cmd.Flags().Args()
|
||||
if len(args) != 1 {
|
||||
cmd.Help()
|
||||
return false
|
||||
return fmt.Errorf("Unexpected args: %v", args)
|
||||
}
|
||||
|
||||
o.name = args[0]
|
||||
return true
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o createClusterOptions) validate() error {
|
||||
|
|
|
@ -59,10 +59,7 @@ func NewCmdConfigSetContext(out io.Writer, configAccess clientcmd.ConfigAccess)
|
|||
Long: create_context_long,
|
||||
Example: create_context_example,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if !options.complete(cmd) {
|
||||
return
|
||||
}
|
||||
|
||||
cmdutil.CheckErr(options.complete(cmd))
|
||||
cmdutil.CheckErr(options.run())
|
||||
fmt.Fprintf(out, "Context %q set.\n", options.name)
|
||||
},
|
||||
|
@ -116,15 +113,15 @@ func (o *createContextOptions) modifyContext(existingContext clientcmdapi.Contex
|
|||
return modifiedContext
|
||||
}
|
||||
|
||||
func (o *createContextOptions) complete(cmd *cobra.Command) bool {
|
||||
func (o *createContextOptions) complete(cmd *cobra.Command) error {
|
||||
args := cmd.Flags().Args()
|
||||
if len(args) != 1 {
|
||||
cmd.Help()
|
||||
return false
|
||||
return fmt.Errorf("Unexpected args: %v", args)
|
||||
}
|
||||
|
||||
o.name = args[0]
|
||||
return true
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o createContextOptions) validate() error {
|
||||
|
|
|
@ -60,10 +60,7 @@ func NewCmdConfigSet(out io.Writer, configAccess clientcmd.ConfigAccess) *cobra.
|
|||
Short: i18n.T("Sets an individual value in a kubeconfig file"),
|
||||
Long: set_long,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if !options.complete(cmd) {
|
||||
return
|
||||
}
|
||||
|
||||
cmdutil.CheckErr(options.complete(cmd))
|
||||
cmdutil.CheckErr(options.run())
|
||||
fmt.Fprintf(out, "Property %q set.\n", options.propertyName)
|
||||
},
|
||||
|
@ -106,16 +103,16 @@ func (o setOptions) run() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (o *setOptions) complete(cmd *cobra.Command) bool {
|
||||
func (o *setOptions) complete(cmd *cobra.Command) error {
|
||||
endingArgs := cmd.Flags().Args()
|
||||
if len(endingArgs) != 2 {
|
||||
cmd.Help()
|
||||
return false
|
||||
return fmt.Errorf("Unexpected args: %v", endingArgs)
|
||||
}
|
||||
|
||||
o.propertyValue = endingArgs[1]
|
||||
o.propertyName = endingArgs[0]
|
||||
return true
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o setOptions) validate() error {
|
||||
|
|
|
@ -48,10 +48,7 @@ func NewCmdConfigUnset(out io.Writer, configAccess clientcmd.ConfigAccess) *cobr
|
|||
Short: i18n.T("Unsets an individual value in a kubeconfig file"),
|
||||
Long: unset_long,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if !options.complete(cmd) {
|
||||
return
|
||||
}
|
||||
|
||||
cmdutil.CheckErr(options.complete(cmd))
|
||||
cmdutil.CheckErr(options.run())
|
||||
fmt.Fprintf(out, "Property %q unset.\n", options.propertyName)
|
||||
},
|
||||
|
@ -87,15 +84,15 @@ func (o unsetOptions) run() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (o *unsetOptions) complete(cmd *cobra.Command) bool {
|
||||
func (o *unsetOptions) complete(cmd *cobra.Command) error {
|
||||
endingArgs := cmd.Flags().Args()
|
||||
if len(endingArgs) != 1 {
|
||||
cmd.Help()
|
||||
return false
|
||||
return fmt.Errorf("Unexpected args: %v", endingArgs)
|
||||
}
|
||||
|
||||
o.propertyName = endingArgs[0]
|
||||
return true
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o unsetOptions) validate() error {
|
||||
|
|
|
@ -50,10 +50,7 @@ func NewCmdConfigUseContext(out io.Writer, configAccess clientcmd.ConfigAccess)
|
|||
Long: `Sets the current-context in a kubeconfig file`,
|
||||
Example: use_context_example,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if !options.complete(cmd) {
|
||||
return
|
||||
}
|
||||
|
||||
cmdutil.CheckErr(options.complete(cmd))
|
||||
cmdutil.CheckErr(options.run())
|
||||
fmt.Fprintf(out, "Switched to context %q.\n", options.contextName)
|
||||
},
|
||||
|
@ -82,15 +79,15 @@ func (o useContextOptions) run() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (o *useContextOptions) complete(cmd *cobra.Command) bool {
|
||||
func (o *useContextOptions) complete(cmd *cobra.Command) error {
|
||||
endingArgs := cmd.Flags().Args()
|
||||
if len(endingArgs) != 1 {
|
||||
cmd.Help()
|
||||
return false
|
||||
return fmt.Errorf("Unexpected args: %v", endingArgs)
|
||||
}
|
||||
|
||||
o.contextName = endingArgs[0]
|
||||
return true
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o useContextOptions) validate(config *clientcmdapi.Config) error {
|
||||
|
|
Loading…
Reference in New Issue