2016-02-15 14:09:34 +01:00
|
|
|
package commands
|
|
|
|
|
|
|
|
|
|
import (
|
2022-08-23 11:50:50 +02:00
|
|
|
"context"
|
2022-06-06 16:30:31 -04:00
|
|
|
"fmt"
|
|
|
|
|
|
2016-05-12 04:43:31 -04:00
|
|
|
"github.com/fatih/color"
|
2016-06-03 12:19:04 +02:00
|
|
|
"github.com/grafana/grafana/pkg/cmd/grafana-cli/logger"
|
2020-03-04 13:18:13 +01:00
|
|
|
"github.com/grafana/grafana/pkg/cmd/grafana-cli/services"
|
2019-05-27 10:47:21 +02:00
|
|
|
"github.com/grafana/grafana/pkg/cmd/grafana-cli/utils"
|
2016-02-15 14:09:34 +01:00
|
|
|
)
|
|
|
|
|
|
2020-02-26 12:27:31 +01:00
|
|
|
func (cmd Command) upgradeCommand(c utils.CommandLine) error {
|
2016-06-24 20:14:58 +02:00
|
|
|
pluginsDir := c.PluginDirectory()
|
2016-02-16 08:49:27 +01:00
|
|
|
pluginName := c.Args().First()
|
|
|
|
|
|
2020-03-04 13:18:13 +01:00
|
|
|
localPlugin, err := services.ReadPlugin(pluginsDir, pluginName)
|
2016-02-16 08:49:27 +01:00
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-26 16:13:40 +02:00
|
|
|
plugin, err2 := cmd.Client.GetPlugin(pluginName, c.PluginRepoURL())
|
2016-02-16 08:49:27 +01:00
|
|
|
if err2 != nil {
|
|
|
|
|
return err2
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-29 10:44:58 +02:00
|
|
|
if shouldUpgrade(localPlugin.Info.Version, &plugin) {
|
2020-03-04 13:18:13 +01:00
|
|
|
if err := services.RemoveInstalledPlugin(pluginsDir, pluginName); err != nil {
|
2022-06-06 16:30:31 -04:00
|
|
|
return fmt.Errorf("failed to remove plugin '%s': %w", pluginName, err)
|
2019-10-15 16:44:15 +02:00
|
|
|
}
|
|
|
|
|
|
2022-08-23 11:50:50 +02:00
|
|
|
return installPlugin(context.Background(), pluginName, "", c)
|
2016-02-16 08:49:27 +01:00
|
|
|
}
|
|
|
|
|
|
2018-09-13 17:19:51 -04:00
|
|
|
logger.Infof("%s %s is up to date \n", color.GreenString("✔"), pluginName)
|
2016-02-16 08:49:27 +01:00
|
|
|
return nil
|
2016-02-15 14:09:34 +01:00
|
|
|
}
|