grafana-cli: update plugins ls command (#63492)

This commit is contained in:
Andres Martinez Gotor 2023-02-22 09:24:13 +01:00 committed by GitHub
parent b069fd81b2
commit 45e478182b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 25 additions and 6 deletions

View File

@ -4,7 +4,6 @@ import (
"fmt"
"strings"
"github.com/fatih/color"
"github.com/urfave/cli/v2"
"github.com/grafana/grafana/pkg/bus"
@ -99,8 +98,6 @@ func runPluginCommand(command func(commandLine utils.CommandLine) error) func(co
if err := command(cmd); err != nil {
return err
}
logger.Info(color.GreenString("Please restart Grafana after installing plugins. Refer to Grafana documentation for instructions if necessary.\n\n"))
return nil
}
}
@ -139,7 +136,7 @@ var pluginCommands = []*cli.Command{
Action: runPluginCommand(cmd.upgradeAllCommand),
}, {
Name: "ls",
Usage: "list all installed plugins",
Usage: "list installed plugins (excludes core plugins)",
Action: runPluginCommand(cmd.lsCommand),
}, {
Name: "uninstall",

View File

@ -8,6 +8,8 @@ import (
"runtime"
"strings"
"github.com/fatih/color"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/logger"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/models"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/services"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/utils"
@ -41,6 +43,10 @@ func validateInput(c utils.CommandLine, pluginFolder string) error {
return nil
}
func logRestartNotice() {
logger.Info(color.GreenString("Please restart Grafana after installing or removing plugins. Refer to Grafana documentation for instructions if necessary.\n\n"))
}
func (cmd Command) installCommand(c utils.CommandLine) error {
pluginFolder := c.PluginDirectory()
if err := validateInput(c, pluginFolder); err != nil {
@ -49,7 +55,11 @@ func (cmd Command) installCommand(c utils.CommandLine) error {
pluginID := c.Args().First()
version := c.Args().Get(1)
return installPlugin(context.Background(), pluginID, version, c)
err := installPlugin(context.Background(), pluginID, version, c)
if err == nil {
logRestartNotice()
}
return err
}
// installPlugin downloads the plugin code as a zip file from the Grafana.com API

View File

@ -45,6 +45,8 @@ func (cmd Command) lsCommand(c utils.CommandLine) error {
if len(plugins) > 0 {
logger.Info("installed plugins:\n")
} else {
logger.Info("no installed plugins found\n")
}
for _, plugin := range plugins {

View File

@ -27,6 +27,8 @@ func (cmd Command) removeCommand(c utils.CommandLine) error {
}
return err
} else {
logRestartNotice()
}
return nil

View File

@ -63,5 +63,9 @@ func (cmd Command) upgradeAllCommand(c utils.CommandLine) error {
}
}
if len(pluginsToUpgrade) > 0 {
logRestartNotice()
}
return nil
}

View File

@ -31,7 +31,11 @@ func (cmd Command) upgradeCommand(c utils.CommandLine) error {
return fmt.Errorf("failed to remove plugin '%s': %w", pluginName, err)
}
return installPlugin(context.Background(), pluginName, "", c)
err := installPlugin(context.Background(), pluginName, "", c)
if err == nil {
logRestartNotice()
}
return err
}
logger.Infof("%s %s is up to date \n", color.GreenString("✔"), pluginName)