@@ -141,25 +141,23 @@ func NewDefaultOcCommand(o kubecmd.KubectlOptions) *cobra.Command {
141141 }
142142 }
143143 } else if err == nil {
144- if ! kcmdutil .CmdPluginAsSubcommand .IsDisabled () {
145- // Command exists(e.g. kubectl create), but it is not certain that
146- // subcommand also exists (e.g. kubectl create networkpolicy)
147- // we also have to eliminate kubectl create -f
148- if kubecmd .IsSubcommandPluginAllowed (foundCmd .Name ()) && len (foundArgs ) >= 1 && ! strings .HasPrefix (foundArgs [0 ], "-" ) {
149- subcommand := foundArgs [0 ]
150- builtinSubcmdExist := false
151- for _ , subcmd := range foundCmd .Commands () {
152- if subcmd .Name () == subcommand {
153- builtinSubcmdExist = true
154- break
155- }
144+ // Command exists(e.g. kubectl create), but it is not certain that
145+ // subcommand also exists (e.g. kubectl create networkpolicy)
146+ // we also have to eliminate kubectl create -f
147+ if kubecmd .IsSubcommandPluginAllowed (foundCmd .Name ()) && len (foundArgs ) >= 1 && ! strings .HasPrefix (foundArgs [0 ], "-" ) {
148+ subcommand := foundArgs [0 ]
149+ builtinSubcmdExist := false
150+ for _ , subcmd := range foundCmd .Commands () {
151+ if subcmd .Name () == subcommand {
152+ builtinSubcmdExist = true
153+ break
156154 }
155+ }
157156
158- if ! builtinSubcmdExist {
159- if err := kubecmd .HandlePluginCommand (o .PluginHandler , cmdPathPieces , len (cmdPathPieces )- len (foundArgs )+ 1 ); err != nil {
160- fmt .Fprintf (o .IOStreams .ErrOut , "Error: %v\n " , err )
161- os .Exit (1 )
162- }
157+ if ! builtinSubcmdExist {
158+ if err := kubecmd .HandlePluginCommand (o .PluginHandler , cmdPathPieces , len (cmdPathPieces )- len (foundArgs )+ 1 ); err != nil {
159+ fmt .Fprintf (o .IOStreams .ErrOut , "Error: %v\n " , err )
160+ os .Exit (1 )
163161 }
164162 }
165163 }
@@ -214,7 +212,7 @@ func NewOcCommand(o kubecmd.KubectlOptions) *cobra.Command {
214212 flags .BoolVar (& warningsAsErrors , "warnings-as-errors" , warningsAsErrors , "Treat warnings received from the server as errors and exit with a non-zero exit code" )
215213
216214 pref := kuberc .NewPreferences ()
217- if kcmdutil .KubeRC .IsEnabled () {
215+ if ! kcmdutil .KubeRC .IsDisabled () {
218216 pref .AddFlags (flags )
219217 }
220218
@@ -341,7 +339,7 @@ func NewOcCommand(o kubecmd.KubectlOptions) *cobra.Command {
341339
342340 registerCompletionFuncForGlobalFlags (cmds , f )
343341
344- if kcmdutil .KubeRC .IsEnabled () {
342+ if ! kcmdutil .KubeRC .IsDisabled () {
345343 _ , err := pref .Apply (cmds , o .Arguments , o .IOStreams .ErrOut )
346344 if err != nil {
347345 fmt .Fprintf (o .IOStreams .ErrOut , "error occurred while applying preferences %v\n " , err )
0 commit comments