mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
grafana-cli: update plugins ls command (#63492)
This commit is contained in:
parent
b069fd81b2
commit
45e478182b
@ -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",
|
||||
|
@ -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
|
||||
|
@ -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 {
|
||||
|
@ -27,6 +27,8 @@ func (cmd Command) removeCommand(c utils.CommandLine) error {
|
||||
}
|
||||
|
||||
return err
|
||||
} else {
|
||||
logRestartNotice()
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -63,5 +63,9 @@ func (cmd Command) upgradeAllCommand(c utils.CommandLine) error {
|
||||
}
|
||||
}
|
||||
|
||||
if len(pluginsToUpgrade) > 0 {
|
||||
logRestartNotice()
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user