Simplify plugin resolution check function
This commit is contained in:
		@@ -142,7 +142,7 @@ func NewDefaultKubectlCommandWithArgs(o KubectlOptions) *cobra.Command {
 | 
				
			|||||||
			if cmdutil.CmdPluginAsSubcommand.IsEnabled() {
 | 
								if cmdutil.CmdPluginAsSubcommand.IsEnabled() {
 | 
				
			||||||
				// Command exists(e.g. kubectl create), but it is not certain that
 | 
									// Command exists(e.g. kubectl create), but it is not certain that
 | 
				
			||||||
				// subcommand also exists (e.g. kubectl create networkpolicy)
 | 
									// subcommand also exists (e.g. kubectl create networkpolicy)
 | 
				
			||||||
				if _, ok := GetAllowedCmdsAsSubcommandPlugins()[foundCmd.Name()]; ok {
 | 
									if IsSubcommandPluginAllowed(foundCmd.Name()) {
 | 
				
			||||||
					var subcommand string
 | 
										var subcommand string
 | 
				
			||||||
					for _, arg := range foundArgs { // first "non-flag" argument as subcommand
 | 
										for _, arg := range foundArgs { // first "non-flag" argument as subcommand
 | 
				
			||||||
						if !strings.HasPrefix(arg, "-") {
 | 
											if !strings.HasPrefix(arg, "-") {
 | 
				
			||||||
@@ -172,11 +172,12 @@ func NewDefaultKubectlCommandWithArgs(o KubectlOptions) *cobra.Command {
 | 
				
			|||||||
	return cmd
 | 
						return cmd
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// GetAllowedCmdsAsSubcommandPlugins returns the list of builtin commands
 | 
					// IsSubcommandPluginAllowed returns the given command is allowed
 | 
				
			||||||
// that plugins are allowed to be used as subcommands only if the passed subcommand
 | 
					// to use plugin as subcommand if the subcommand does not exist as builtin.
 | 
				
			||||||
// does not exist as builtin.
 | 
					func IsSubcommandPluginAllowed(foundCmd string) bool {
 | 
				
			||||||
func GetAllowedCmdsAsSubcommandPlugins() map[string]struct{} {
 | 
						allowedCmds := map[string]struct{}{"create": {}}
 | 
				
			||||||
	return map[string]struct{}{"create": {}}
 | 
						_, ok := allowedCmds[foundCmd]
 | 
				
			||||||
 | 
						return ok
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// PluginHandler is capable of parsing command line arguments
 | 
					// PluginHandler is capable of parsing command line arguments
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user