|
|
|
@ -29,16 +29,22 @@ import (
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type pluginUpdateOptions struct {
|
|
|
|
|
names []string
|
|
|
|
|
names map[string]string
|
|
|
|
|
version string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const pluginUpdateDesc = `
|
|
|
|
|
This command allows you to update one or more Helm plugins.
|
|
|
|
|
`
|
|
|
|
|
|
|
|
|
|
func newPluginUpdateCmd(out io.Writer) *cobra.Command {
|
|
|
|
|
o := &pluginUpdateOptions{}
|
|
|
|
|
|
|
|
|
|
cmd := &cobra.Command{
|
|
|
|
|
Use: "update <plugin>...",
|
|
|
|
|
Use: "update <plugin:[version]>...",
|
|
|
|
|
Aliases: []string{"up"},
|
|
|
|
|
Short: "update one or more Helm plugins",
|
|
|
|
|
Long: pluginUpdateDesc,
|
|
|
|
|
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
|
|
|
|
return compListPlugins(toComplete, args), cobra.ShellCompDirectiveNoFileComp
|
|
|
|
|
},
|
|
|
|
@ -49,6 +55,7 @@ func newPluginUpdateCmd(out io.Writer) *cobra.Command {
|
|
|
|
|
return o.run(out)
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
cmd.Flags().StringVar(&o.version, "version", "", "specify a version constraint. If this is not specified, the latest version is installed")
|
|
|
|
|
return cmd
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -56,7 +63,14 @@ func (o *pluginUpdateOptions) complete(args []string) error {
|
|
|
|
|
if len(args) == 0 {
|
|
|
|
|
return errors.New("please provide plugin name to update")
|
|
|
|
|
}
|
|
|
|
|
o.names = args
|
|
|
|
|
o.names = make(map[string]string)
|
|
|
|
|
for _, arg := range args {
|
|
|
|
|
if strings.ContainsAny(arg, ":") {
|
|
|
|
|
o.names[arg[:strings.LastIndex(arg, ":")]] = arg[strings.LastIndex(arg, ":")+1:]
|
|
|
|
|
} else {
|
|
|
|
|
o.names[arg] = ""
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -68,10 +82,9 @@ func (o *pluginUpdateOptions) run(out io.Writer) error {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
var errorPlugins []string
|
|
|
|
|
|
|
|
|
|
for _, name := range o.names {
|
|
|
|
|
for name, version := range o.names {
|
|
|
|
|
if found := findPlugin(plugins, name); found != nil {
|
|
|
|
|
if err := updatePlugin(found); err != nil {
|
|
|
|
|
if err := updatePlugin(found, version); err != nil {
|
|
|
|
|
errorPlugins = append(errorPlugins, fmt.Sprintf("Failed to update plugin %s, got error (%v)", name, err))
|
|
|
|
|
} else {
|
|
|
|
|
fmt.Fprintf(out, "Updated plugin: %s\n", name)
|
|
|
|
@ -86,7 +99,7 @@ func (o *pluginUpdateOptions) run(out io.Writer) error {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func updatePlugin(p *plugin.Plugin) error {
|
|
|
|
|
func updatePlugin(p *plugin.Plugin, version string) error {
|
|
|
|
|
exactLocation, err := filepath.EvalSymlinks(p.Dir)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
@ -96,7 +109,7 @@ func updatePlugin(p *plugin.Plugin) error {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
i, err := installer.FindSource(absExactLocation)
|
|
|
|
|
i, err := installer.FindSource(absExactLocation, version)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|