Commit 74625771 by bergquist

fix(cli): align code with core grafana

parent 9c50b89d
......@@ -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 . <service grafana-server restart>\n")
}
......
......@@ -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)
......
......@@ -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
......
......@@ -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)
}
}
......
......@@ -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, "")
}
......
......@@ -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",
......
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