make sure a plugin command name does not already exist

Signed-off-by: SataQiu <qiushida@beyondcent.com>
pull/5195/head
SataQiu 7 years ago
parent 4c226b67f9
commit c2c16fceb4

@ -44,6 +44,8 @@ var (
settings helm_env.EnvSettings
)
var RootCmd *cobra.Command
var globalUsage = `The Kubernetes package manager
To begin working with Helm, run the 'helm init' command:
@ -157,6 +159,8 @@ func newRootCmd(args []string) *cobra.Command {
// Find and add plugins
loadPlugins(cmd, out)
RootCmd = cmd
return cmd
}

@ -23,22 +23,12 @@ import (
"path/filepath"
"strings"
"syscall"
"text/template"
"github.com/spf13/cobra"
"k8s.io/helm/pkg/plugin"
)
var pluginLoadWarningTemp = template.Must(template.New("plugin").Parse(`
Helm Client Plugin Load Warning(s):
{{range $_, $warning := .Warnings}}
- {{ $warning }}
{{end}}
In order to eliminate this warning(s), please try to uninstall or reinstall the plugin(s) in question.
------------------------------------------------------------------------------------------------------
`))
type pluginError struct {
error
code int
@ -72,8 +62,6 @@ func loadPlugins(baseCmd *cobra.Command, out io.Writer) {
}
// Now we create commands for all of these.
warnings := []string{}
loop:
for _, plug := range found {
plug := plug
md := plug.Metadata
@ -129,22 +117,9 @@ loop:
}
}
// Make sure a command with this name does not already exist.
for _, cmd := range baseCmd.Commands() {
if cmd.Name() == md.Name {
warning := fmt.Sprintf("A command with the name of [%s] already exists, so the plugin at [%s] will not be loaded.", md.Name, plug.Dir)
warnings = append(warnings, warning)
continue loop
}
}
// TODO: Make sure a command with this name does not already exist.
baseCmd.AddCommand(c)
}
ctx := map[string]interface{}{
"Warnings": warnings,
}
pluginLoadWarningTemp.Execute(out, ctx)
}
// manuallyProcessArgs processes an arg array, removing special args.

@ -18,6 +18,7 @@ package main
import (
"fmt"
"io"
"os"
"k8s.io/helm/pkg/helm/helmpath"
"k8s.io/helm/pkg/plugin"
@ -83,10 +84,20 @@ func (pcmd *pluginInstallCmd) run() error {
return err
}
// Make sure a command with this name does not already exist.
pluginCmdName := p.Metadata.Name
for _, cmd := range RootCmd.Commands() {
if cmd.Name() == pluginCmdName {
os.Remove(p.Dir)
err = fmt.Errorf("Plugin <%s> not installed as plugin with that name is already installed.", pluginCmdName)
return err
}
}
if err := runHook(p, plugin.Install); err != nil {
return err
}
fmt.Fprintf(pcmd.out, "Installed plugin: %s\n", p.Metadata.Name)
fmt.Fprintf(pcmd.out, "Installed plugin: %s\n", pluginCmdName)
return nil
}

Loading…
Cancel
Save