From 746257710b7adc3825cbe5aa7b21b76dade3440b Mon Sep 17 00:00:00 2001 From: bergquist Date: Mon, 15 Feb 2016 16:11:37 +0100 Subject: [PATCH] fix(cli): align code with core grafana --- pkg/cmd/grafana-cli/commands/commands.go | 2 ++ pkg/cmd/grafana-cli/commands/install_command.go | 6 +++--- pkg/cmd/grafana-cli/commands/listremote_command.go | 4 ++-- pkg/cmd/grafana-cli/commands/remove_command.go | 4 ++-- pkg/cmd/grafana-cli/commands/upgrade_all_command.go | 10 +++++----- pkg/cmd/grafana-cli/main.go | 5 +++-- pkg/cmd/grafana-cli/version/version.go | 5 ----- 7 files changed, 17 insertions(+), 19 deletions(-) delete mode 100644 pkg/cmd/grafana-cli/version/version.go diff --git a/pkg/cmd/grafana-cli/commands/commands.go b/pkg/cmd/grafana-cli/commands/commands.go index 7854e45b77a..55e9a771480 100644 --- a/pkg/cmd/grafana-cli/commands/commands.go +++ b/pkg/cmd/grafana-cli/commands/commands.go @@ -3,6 +3,7 @@ package commands import ( "github.com/codegangsta/cli" "github.com/grafana/grafana/pkg/cmd/grafana-cli/log" + "os" ) func runCommand(command func(commandLine CommandLine) error) func(context *cli.Context) { @@ -13,6 +14,7 @@ func runCommand(command func(commandLine CommandLine) error) func(context *cli.C log.Errorf("%v\n\n", err) cmd.ShowHelp() + os.Exit(1) } else { log.Info("Restart grafana after installing plugins . \n") } diff --git a/pkg/cmd/grafana-cli/commands/install_command.go b/pkg/cmd/grafana-cli/commands/install_command.go index f3de4cfb5d6..6c7970147aa 100644 --- a/pkg/cmd/grafana-cli/commands/install_command.go +++ b/pkg/cmd/grafana-cli/commands/install_command.go @@ -6,7 +6,7 @@ import ( "errors" "github.com/grafana/grafana/pkg/cmd/grafana-cli/log" m "github.com/grafana/grafana/pkg/cmd/grafana-cli/models" - services "github.com/grafana/grafana/pkg/cmd/grafana-cli/services" + s "github.com/grafana/grafana/pkg/cmd/grafana-cli/services" "io" "io/ioutil" "net/http" @@ -49,7 +49,7 @@ func installCommand(c CommandLine) error { } func InstallPlugin(pluginName, pluginFolder, version string) error { - plugin, err := services.GetPlugin(pluginName) + plugin, err := s.GetPlugin(pluginName) if err != nil { return err } @@ -74,7 +74,7 @@ func InstallPlugin(pluginName, pluginFolder, version string) error { log.Info("Installed %s successfully ✔\n", plugin.Id) } - res := services.ReadPlugin(pluginFolder, pluginName) + res := s.ReadPlugin(pluginFolder, pluginName) for _, v := range res.Dependency.Plugins { log.Infof("Installing Dependency: %s\n", v.Id) diff --git a/pkg/cmd/grafana-cli/commands/listremote_command.go b/pkg/cmd/grafana-cli/commands/listremote_command.go index 5adda217be1..cf535a0498e 100644 --- a/pkg/cmd/grafana-cli/commands/listremote_command.go +++ b/pkg/cmd/grafana-cli/commands/listremote_command.go @@ -2,11 +2,11 @@ package commands import ( "github.com/grafana/grafana/pkg/cmd/grafana-cli/log" - "github.com/grafana/grafana/pkg/cmd/grafana-cli/services" + s "github.com/grafana/grafana/pkg/cmd/grafana-cli/services" ) func listremoteCommand(c CommandLine) error { - plugin, err := services.ListAllPlugins() + plugin, err := s.ListAllPlugins() if err != nil { return err diff --git a/pkg/cmd/grafana-cli/commands/remove_command.go b/pkg/cmd/grafana-cli/commands/remove_command.go index 86a3ccc9809..1235d257ab6 100644 --- a/pkg/cmd/grafana-cli/commands/remove_command.go +++ b/pkg/cmd/grafana-cli/commands/remove_command.go @@ -19,14 +19,14 @@ func removeCommand(c CommandLine) error { plugin := c.Args().First() log.Info("plugin: " + plugin + "\n") if plugin == "" { - return errors.New("Missing which plugin parameter") + return errors.New("Missing plugin parameter") } log.Infof("plugins : \n%v\n", localPlugins) for _, p := range localPlugins { - log.Infof("is %s == %s ? %v", p.Id, c.Args().First(), p.Id == c.Args().First()) if p.Id == c.Args().First() { + log.Infof("removing plugin %s", p.Id) removePlugin(pluginPath, p.Id) } } diff --git a/pkg/cmd/grafana-cli/commands/upgrade_all_command.go b/pkg/cmd/grafana-cli/commands/upgrade_all_command.go index 04d6cea840a..6c1e0182f51 100644 --- a/pkg/cmd/grafana-cli/commands/upgrade_all_command.go +++ b/pkg/cmd/grafana-cli/commands/upgrade_all_command.go @@ -3,7 +3,7 @@ package commands import ( "github.com/grafana/grafana/pkg/cmd/grafana-cli/log" m "github.com/grafana/grafana/pkg/cmd/grafana-cli/models" - services "github.com/grafana/grafana/pkg/cmd/grafana-cli/services" + s "github.com/grafana/grafana/pkg/cmd/grafana-cli/services" "github.com/hashicorp/go-version" ) @@ -30,9 +30,9 @@ func ShouldUpgrade(installed string, remote m.Plugin) bool { func upgradeAllCommand(c CommandLine) error { pluginDir := c.GlobalString("path") - localPlugins := services.GetLocalPlugins(pluginDir) + localPlugins := s.GetLocalPlugins(pluginDir) - remotePlugins, err := services.ListAllPlugins() + remotePlugins, err := s.ListAllPlugins() if err != nil { return err @@ -51,9 +51,9 @@ func upgradeAllCommand(c CommandLine) error { } for _, p := range pluginsToUpgrade { - log.Infof("lets upgrade %v \n", p) + log.Infof("Upgrading %v \n", p.Id) - services.RemoveInstalledPlugin(pluginDir, p.Id) + s.RemoveInstalledPlugin(pluginDir, p.Id) InstallPlugin(p.Id, pluginDir, "") } diff --git a/pkg/cmd/grafana-cli/main.go b/pkg/cmd/grafana-cli/main.go index a04d1511397..938cfcc284a 100644 --- a/pkg/cmd/grafana-cli/main.go +++ b/pkg/cmd/grafana-cli/main.go @@ -5,11 +5,12 @@ import ( "github.com/codegangsta/cli" "github.com/grafana/grafana/pkg/cmd/grafana-cli/commands" "github.com/grafana/grafana/pkg/cmd/grafana-cli/log" - "github.com/grafana/grafana/pkg/cmd/grafana-cli/version" "os" "runtime" ) +var version = "master" + func getGrafanaPluginPath() string { //TODO: try to get path from os:env GF_PLUGIN_FOLDER @@ -28,7 +29,7 @@ func main() { app.Name = "Grafana cli" app.Author = "raintank" app.Email = "https://github.com/grafana/grafana" - app.Version = version.Version + app.Version = version app.Flags = []cli.Flag{ cli.StringFlag{ Name: "path", diff --git a/pkg/cmd/grafana-cli/version/version.go b/pkg/cmd/grafana-cli/version/version.go deleted file mode 100644 index 2a0eddf9859..00000000000 --- a/pkg/cmd/grafana-cli/version/version.go +++ /dev/null @@ -1,5 +0,0 @@ -package version - -var ( - Version = "0.0.2" -)