Commit 74625771 by bergquist

fix(cli): align code with core grafana

parent 9c50b89d
...@@ -3,6 +3,7 @@ package commands ...@@ -3,6 +3,7 @@ package commands
import ( import (
"github.com/codegangsta/cli" "github.com/codegangsta/cli"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/log" "github.com/grafana/grafana/pkg/cmd/grafana-cli/log"
"os"
) )
func runCommand(command func(commandLine CommandLine) error) func(context *cli.Context) { 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 ...@@ -13,6 +14,7 @@ func runCommand(command func(commandLine CommandLine) error) func(context *cli.C
log.Errorf("%v\n\n", err) log.Errorf("%v\n\n", err)
cmd.ShowHelp() cmd.ShowHelp()
os.Exit(1)
} else { } else {
log.Info("Restart grafana after installing plugins . <service grafana-server restart>\n") log.Info("Restart grafana after installing plugins . <service grafana-server restart>\n")
} }
......
...@@ -6,7 +6,7 @@ import ( ...@@ -6,7 +6,7 @@ import (
"errors" "errors"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/log" "github.com/grafana/grafana/pkg/cmd/grafana-cli/log"
m "github.com/grafana/grafana/pkg/cmd/grafana-cli/models" 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"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
...@@ -49,7 +49,7 @@ func installCommand(c CommandLine) error { ...@@ -49,7 +49,7 @@ func installCommand(c CommandLine) error {
} }
func InstallPlugin(pluginName, pluginFolder, version string) error { func InstallPlugin(pluginName, pluginFolder, version string) error {
plugin, err := services.GetPlugin(pluginName) plugin, err := s.GetPlugin(pluginName)
if err != nil { if err != nil {
return err return err
} }
...@@ -74,7 +74,7 @@ func InstallPlugin(pluginName, pluginFolder, version string) error { ...@@ -74,7 +74,7 @@ func InstallPlugin(pluginName, pluginFolder, version string) error {
log.Info("Installed %s successfully ✔\n", plugin.Id) log.Info("Installed %s successfully ✔\n", plugin.Id)
} }
res := services.ReadPlugin(pluginFolder, pluginName) res := s.ReadPlugin(pluginFolder, pluginName)
for _, v := range res.Dependency.Plugins { for _, v := range res.Dependency.Plugins {
log.Infof("Installing Dependency: %s\n", v.Id) log.Infof("Installing Dependency: %s\n", v.Id)
......
...@@ -2,11 +2,11 @@ package commands ...@@ -2,11 +2,11 @@ package commands
import ( import (
"github.com/grafana/grafana/pkg/cmd/grafana-cli/log" "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 { func listremoteCommand(c CommandLine) error {
plugin, err := services.ListAllPlugins() plugin, err := s.ListAllPlugins()
if err != nil { if err != nil {
return err return err
......
...@@ -19,14 +19,14 @@ func removeCommand(c CommandLine) error { ...@@ -19,14 +19,14 @@ func removeCommand(c CommandLine) error {
plugin := c.Args().First() plugin := c.Args().First()
log.Info("plugin: " + plugin + "\n") log.Info("plugin: " + plugin + "\n")
if plugin == "" { if plugin == "" {
return errors.New("Missing which plugin parameter") return errors.New("Missing plugin parameter")
} }
log.Infof("plugins : \n%v\n", localPlugins) log.Infof("plugins : \n%v\n", localPlugins)
for _, p := range 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() { if p.Id == c.Args().First() {
log.Infof("removing plugin %s", p.Id)
removePlugin(pluginPath, p.Id) removePlugin(pluginPath, p.Id)
} }
} }
......
...@@ -3,7 +3,7 @@ package commands ...@@ -3,7 +3,7 @@ package commands
import ( import (
"github.com/grafana/grafana/pkg/cmd/grafana-cli/log" "github.com/grafana/grafana/pkg/cmd/grafana-cli/log"
m "github.com/grafana/grafana/pkg/cmd/grafana-cli/models" 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" "github.com/hashicorp/go-version"
) )
...@@ -30,9 +30,9 @@ func ShouldUpgrade(installed string, remote m.Plugin) bool { ...@@ -30,9 +30,9 @@ func ShouldUpgrade(installed string, remote m.Plugin) bool {
func upgradeAllCommand(c CommandLine) error { func upgradeAllCommand(c CommandLine) error {
pluginDir := c.GlobalString("path") pluginDir := c.GlobalString("path")
localPlugins := services.GetLocalPlugins(pluginDir) localPlugins := s.GetLocalPlugins(pluginDir)
remotePlugins, err := services.ListAllPlugins() remotePlugins, err := s.ListAllPlugins()
if err != nil { if err != nil {
return err return err
...@@ -51,9 +51,9 @@ func upgradeAllCommand(c CommandLine) error { ...@@ -51,9 +51,9 @@ func upgradeAllCommand(c CommandLine) error {
} }
for _, p := range pluginsToUpgrade { 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, "") InstallPlugin(p.Id, pluginDir, "")
} }
......
...@@ -5,11 +5,12 @@ import ( ...@@ -5,11 +5,12 @@ import (
"github.com/codegangsta/cli" "github.com/codegangsta/cli"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/commands" "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/log"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/version"
"os" "os"
"runtime" "runtime"
) )
var version = "master"
func getGrafanaPluginPath() string { func getGrafanaPluginPath() string {
//TODO: try to get path from os:env GF_PLUGIN_FOLDER //TODO: try to get path from os:env GF_PLUGIN_FOLDER
...@@ -28,7 +29,7 @@ func main() { ...@@ -28,7 +29,7 @@ func main() {
app.Name = "Grafana cli" app.Name = "Grafana cli"
app.Author = "raintank" app.Author = "raintank"
app.Email = "https://github.com/grafana/grafana" app.Email = "https://github.com/grafana/grafana"
app.Version = version.Version app.Version = version
app.Flags = []cli.Flag{ app.Flags = []cli.Flag{
cli.StringFlag{ cli.StringFlag{
Name: "path", Name: "path",
......
package version
var (
Version = "0.0.2"
)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment