mirror of https://github.com/docker/cli.git
Merge pull request #3796 from thaJeztah/add_is_plugincommand_utility
cli-plugins/manager: add IsPluginCommand(() utility
This commit is contained in:
commit
fed93645f1
|
@ -224,3 +224,8 @@ func PluginRunCommand(dockerCli command.Cli, name string, rootcmd *cobra.Command
|
||||||
}
|
}
|
||||||
return nil, errPluginNotFound(name)
|
return nil, errPluginNotFound(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsPluginCommand checks if the given cmd is a plugin-stub.
|
||||||
|
func IsPluginCommand(cmd *cobra.Command) bool {
|
||||||
|
return cmd.Annotations[CommandAnnotationPlugin] == "true"
|
||||||
|
}
|
||||||
|
|
|
@ -69,7 +69,7 @@ func newPlugin(c Candidate, rootcmd *cobra.Command) (Plugin, error) {
|
||||||
// Ignore conflicts with commands which are
|
// Ignore conflicts with commands which are
|
||||||
// just plugin stubs (i.e. from a previous
|
// just plugin stubs (i.e. from a previous
|
||||||
// call to AddPluginCommandStubs).
|
// call to AddPluginCommandStubs).
|
||||||
if p := cmd.Annotations[CommandAnnotationPlugin]; p == "true" {
|
if IsPluginCommand(cmd) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if cmd.Name() == p.Name {
|
if cmd.Name() == p.Name {
|
||||||
|
|
|
@ -237,7 +237,7 @@ func hasAdditionalHelp(cmd *cobra.Command) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func isPlugin(cmd *cobra.Command) bool {
|
func isPlugin(cmd *cobra.Command) bool {
|
||||||
return cmd.Annotations[pluginmanager.CommandAnnotationPlugin] == "true"
|
return pluginmanager.IsPluginCommand(cmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
func hasAliases(cmd *cobra.Command) bool {
|
func hasAliases(cmd *cobra.Command) bool {
|
||||||
|
|
|
@ -28,7 +28,7 @@ func processAliases(dockerCli command.Cli, cmd *cobra.Command, args, osArgs []st
|
||||||
return args, osArgs, errors.Errorf("not allowed to alias %q (allowed: %#v)", k, allowedAliases)
|
return args, osArgs, errors.Errorf("not allowed to alias %q (allowed: %#v)", k, allowedAliases)
|
||||||
}
|
}
|
||||||
if c, _, err := cmd.Find(strings.Split(v, " ")); err == nil {
|
if c, _, err := cmd.Find(strings.Split(v, " ")); err == nil {
|
||||||
if c.Annotations[pluginmanager.CommandAnnotationPlugin] != "true" {
|
if !pluginmanager.IsPluginCommand(c) {
|
||||||
return args, osArgs, errors.Errorf("not allowed to alias with builtin %q as target", v)
|
return args, osArgs, errors.Errorf("not allowed to alias with builtin %q as target", v)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -131,7 +131,7 @@ func tryRunPluginHelp(dockerCli command.Cli, ccmd *cobra.Command, cargs []string
|
||||||
func setHelpFunc(dockerCli command.Cli, cmd *cobra.Command) {
|
func setHelpFunc(dockerCli command.Cli, cmd *cobra.Command) {
|
||||||
defaultHelpFunc := cmd.HelpFunc()
|
defaultHelpFunc := cmd.HelpFunc()
|
||||||
cmd.SetHelpFunc(func(ccmd *cobra.Command, args []string) {
|
cmd.SetHelpFunc(func(ccmd *cobra.Command, args []string) {
|
||||||
if ccmd.Annotations[pluginmanager.CommandAnnotationPlugin] == "true" {
|
if pluginmanager.IsPluginCommand(ccmd) {
|
||||||
err := tryRunPluginHelp(dockerCli, ccmd, args)
|
err := tryRunPluginHelp(dockerCli, ccmd, args)
|
||||||
if !pluginmanager.IsNotFound(err) {
|
if !pluginmanager.IsNotFound(err) {
|
||||||
ccmd.Println(err)
|
ccmd.Println(err)
|
||||||
|
@ -229,8 +229,8 @@ func runDocker(dockerCli *command.DockerCli) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(args) > 0 {
|
if len(args) > 0 {
|
||||||
command, _, err := cmd.Find(args)
|
ccmd, _, err := cmd.Find(args)
|
||||||
if err != nil || command.Annotations[pluginmanager.CommandAnnotationPlugin] == "true" {
|
if err != nil || pluginmanager.IsPluginCommand(ccmd) {
|
||||||
err := tryPluginRun(dockerCli, cmd, args[0])
|
err := tryPluginRun(dockerCli, cmd, args[0])
|
||||||
if !pluginmanager.IsNotFound(err) {
|
if !pluginmanager.IsNotFound(err) {
|
||||||
return err
|
return err
|
||||||
|
|
Loading…
Reference in New Issue