mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
* move guts from cli to server * renaming + refactoring * add pluginsDir arg * arg fixes * add support for repo URL override * add funcs to interface * use pluginID consistently * swap args * pass mandatory grafanaVersion field * introduce logger interface * create central logger for CLI * add infra log wrapper * re-add log initer step * remove unused logger * add checks for uninstalling * improve debug blue * make sure to close file * fix linter issues * remove space * improve newline usage * refactor packaging * improve logger API * fix interface func names * close file and reformat zipslip catch * handle G305 linter warning * add helpful debug log
37 lines
975 B
Go
37 lines
975 B
Go
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
|
|
}
|