From 39be7cf7d752d6d6dbaf396a8d925d808dccb7bb Mon Sep 17 00:00:00 2001 From: Mark Henderson Date: Wed, 27 Jul 2016 03:41:33 -0400 Subject: [PATCH] Added grafana-cli command. Added public documentation for specifying plugin version when installing. (#5665) --- pkg/cmd/grafana-cli/commands/commands.go | 6 +++- .../commands/listversions_command.go | 36 +++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 pkg/cmd/grafana-cli/commands/listversions_command.go diff --git a/pkg/cmd/grafana-cli/commands/commands.go b/pkg/cmd/grafana-cli/commands/commands.go index 3f8826ce8ba..2099a576647 100644 --- a/pkg/cmd/grafana-cli/commands/commands.go +++ b/pkg/cmd/grafana-cli/commands/commands.go @@ -27,12 +27,16 @@ func runCommand(command func(commandLine CommandLine) error) func(context *cli.C var pluginCommands = []cli.Command{ { Name: "install", - Usage: "install ", + Usage: "install ", Action: runCommand(installCommand), }, { Name: "list-remote", Usage: "list remote available plugins", Action: runCommand(listremoteCommand), + }, { + Name: "list-versions", + Usage: "list-versions ", + Action: runCommand(listversionsCommand), }, { Name: "update", Usage: "update ", diff --git a/pkg/cmd/grafana-cli/commands/listversions_command.go b/pkg/cmd/grafana-cli/commands/listversions_command.go new file mode 100644 index 00000000000..95c536e94f0 --- /dev/null +++ b/pkg/cmd/grafana-cli/commands/listversions_command.go @@ -0,0 +1,36 @@ +package commands + +import ( + "errors" + + "github.com/grafana/grafana/pkg/cmd/grafana-cli/logger" + s "github.com/grafana/grafana/pkg/cmd/grafana-cli/services" +) + +func validateVersionInput(c CommandLine) error { + arg := c.Args().First() + if arg == "" { + return errors.New("please specify plugin to list versions for") + } + + return nil +} + +func listversionsCommand(c CommandLine) error { + if err := validateVersionInput(c); err != nil { + return err + } + + pluginToList := c.Args().First() + + plugin, err := s.GetPlugin(pluginToList, c.GlobalString("repo")) + if err != nil { + return err + } + + for _, i := range plugin.Versions { + logger.Infof("%v\n", i.Version) + } + + return nil +}