forked from grafana.jool/grafana-jool
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
975 B
36 lines
975 B
package commands
|
|
|
|
import (
|
|
"github.com/fatih/color"
|
|
"github.com/grafana/grafana/pkg/cmd/grafana-cli/logger"
|
|
"github.com/grafana/grafana/pkg/cmd/grafana-cli/services"
|
|
"github.com/grafana/grafana/pkg/cmd/grafana-cli/utils"
|
|
"github.com/grafana/grafana/pkg/util/errutil"
|
|
)
|
|
|
|
func (cmd Command) upgradeCommand(c utils.CommandLine) error {
|
|
pluginsDir := c.PluginDirectory()
|
|
pluginName := c.Args().First()
|
|
|
|
localPlugin, err := services.ReadPlugin(pluginsDir, pluginName)
|
|
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
plugin, err2 := cmd.Client.GetPlugin(pluginName, c.PluginRepoURL())
|
|
if err2 != nil {
|
|
return err2
|
|
}
|
|
|
|
if shouldUpgrade(localPlugin.Info.Version, &plugin) {
|
|
if err := services.RemoveInstalledPlugin(pluginsDir, pluginName); err != nil {
|
|
return errutil.Wrapf(err, "failed to remove plugin '%s'", pluginName)
|
|
}
|
|
|
|
return InstallPlugin(pluginName, "", c, cmd.Client)
|
|
}
|
|
|
|
logger.Infof("%s %s is up to date \n", color.GreenString("✔"), pluginName)
|
|
return nil
|
|
}
|
|
|