grafana-cli: update plugins ls command (#63492)
This commit is contained in:
@@ -4,7 +4,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/fatih/color"
|
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
|
|
||||||
"github.com/grafana/grafana/pkg/bus"
|
"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 {
|
if err := command(cmd); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.Info(color.GreenString("Please restart Grafana after installing plugins. Refer to Grafana documentation for instructions if necessary.\n\n"))
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -139,7 +136,7 @@ var pluginCommands = []*cli.Command{
|
|||||||
Action: runPluginCommand(cmd.upgradeAllCommand),
|
Action: runPluginCommand(cmd.upgradeAllCommand),
|
||||||
}, {
|
}, {
|
||||||
Name: "ls",
|
Name: "ls",
|
||||||
Usage: "list all installed plugins",
|
Usage: "list installed plugins (excludes core plugins)",
|
||||||
Action: runPluginCommand(cmd.lsCommand),
|
Action: runPluginCommand(cmd.lsCommand),
|
||||||
}, {
|
}, {
|
||||||
Name: "uninstall",
|
Name: "uninstall",
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ import (
|
|||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"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/models"
|
||||||
"github.com/grafana/grafana/pkg/cmd/grafana-cli/services"
|
"github.com/grafana/grafana/pkg/cmd/grafana-cli/services"
|
||||||
"github.com/grafana/grafana/pkg/cmd/grafana-cli/utils"
|
"github.com/grafana/grafana/pkg/cmd/grafana-cli/utils"
|
||||||
@@ -41,6 +43,10 @@ func validateInput(c utils.CommandLine, pluginFolder string) error {
|
|||||||
return nil
|
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 {
|
func (cmd Command) installCommand(c utils.CommandLine) error {
|
||||||
pluginFolder := c.PluginDirectory()
|
pluginFolder := c.PluginDirectory()
|
||||||
if err := validateInput(c, pluginFolder); err != nil {
|
if err := validateInput(c, pluginFolder); err != nil {
|
||||||
@@ -49,7 +55,11 @@ func (cmd Command) installCommand(c utils.CommandLine) error {
|
|||||||
|
|
||||||
pluginID := c.Args().First()
|
pluginID := c.Args().First()
|
||||||
version := c.Args().Get(1)
|
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
|
// 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 {
|
if len(plugins) > 0 {
|
||||||
logger.Info("installed plugins:\n")
|
logger.Info("installed plugins:\n")
|
||||||
|
} else {
|
||||||
|
logger.Info("no installed plugins found\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, plugin := range plugins {
|
for _, plugin := range plugins {
|
||||||
|
|||||||
@@ -27,6 +27,8 @@ func (cmd Command) removeCommand(c utils.CommandLine) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return err
|
return err
|
||||||
|
} else {
|
||||||
|
logRestartNotice()
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -63,5 +63,9 @@ func (cmd Command) upgradeAllCommand(c utils.CommandLine) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(pluginsToUpgrade) > 0 {
|
||||||
|
logRestartNotice()
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
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 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)
|
logger.Infof("%s %s is up to date \n", color.GreenString("✔"), pluginName)
|
||||||
|
|||||||
Reference in New Issue
Block a user