feat(cli): add command for upgrading one plugin
This commit is contained in:
@@ -16,7 +16,7 @@ func runCommand(command func(commandLine CommandLine) error) func(context *cli.C
|
||||
cmd.ShowHelp()
|
||||
os.Exit(1)
|
||||
} else {
|
||||
log.Info("Restart grafana after installing plugins . <service grafana-server restart>\n")
|
||||
log.Info("\nRestart grafana after installing plugins . <service grafana-server restart>\n\n")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,7 @@ func runCommand(command func(commandLine CommandLine) error) func(context *cli.C
|
||||
var Commands = []cli.Command{
|
||||
{
|
||||
Name: "install",
|
||||
Usage: "installs a plugin",
|
||||
Usage: "install <plugin name>",
|
||||
Action: runCommand(installCommand),
|
||||
}, {
|
||||
Name: "list-remote",
|
||||
@@ -32,7 +32,7 @@ var Commands = []cli.Command{
|
||||
Action: runCommand(listremoteCommand),
|
||||
}, {
|
||||
Name: "upgrade",
|
||||
Usage: "upgrades one plugin",
|
||||
Usage: "upgrade <plugin name>",
|
||||
Action: runCommand(upgradeCommand),
|
||||
}, {
|
||||
Name: "upgrade-all",
|
||||
@@ -44,7 +44,7 @@ var Commands = []cli.Command{
|
||||
Action: runCommand(lsCommand),
|
||||
}, {
|
||||
Name: "remove",
|
||||
Usage: "removes installed plugin",
|
||||
Usage: "remove <plugin name>",
|
||||
Action: runCommand(removeCommand),
|
||||
},
|
||||
}
|
||||
|
||||
@@ -71,15 +71,14 @@ func InstallPlugin(pluginName, pluginFolder, version string) error {
|
||||
|
||||
err = downloadFile(plugin.Id, pluginFolder, downloadURL)
|
||||
if err == nil {
|
||||
log.Info("Installed %s successfully ✔\n", plugin.Id)
|
||||
log.Infof("Installed %v successfully ✔\n", plugin.Id)
|
||||
}
|
||||
|
||||
res := s.ReadPlugin(pluginFolder, pluginName)
|
||||
res, _ := s.ReadPlugin(pluginFolder, pluginName)
|
||||
|
||||
for _, v := range res.Dependency.Plugins {
|
||||
log.Infof("Installing Dependency: %s\n", v.Id)
|
||||
|
||||
InstallPlugin(v.Id, pluginFolder, "")
|
||||
log.Infof("Installed Dependency: %v ✔\n", v.Id)
|
||||
}
|
||||
|
||||
return err
|
||||
|
||||
@@ -1,9 +1,33 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"errors"
|
||||
s "github.com/grafana/grafana/pkg/cmd/grafana-cli/services"
|
||||
)
|
||||
|
||||
func upgradeCommand(c CommandLine) error {
|
||||
return errors.New("Not yet Implemented")
|
||||
pluginDir := c.GlobalString("path")
|
||||
pluginName := c.Args().First()
|
||||
|
||||
localPlugin, err := s.ReadPlugin(pluginDir, pluginName)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
remotePlugins, err2 := s.ListAllPlugins()
|
||||
|
||||
if err2 != nil {
|
||||
return err2
|
||||
}
|
||||
|
||||
for _, v := range remotePlugins.Plugins {
|
||||
if localPlugin.Id == v.Id {
|
||||
if ShouldUpgrade(localPlugin.Info.Version, v) {
|
||||
s.RemoveInstalledPlugin(pluginDir, pluginName)
|
||||
return InstallPlugin(localPlugin.Id, pluginDir, "")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user