Commit 1e44ee9e by Torkel Ödegaard

feat(grafana-cli): minor changes

parent b3bda2aa
...@@ -5,10 +5,6 @@ import ( ...@@ -5,10 +5,6 @@ import (
"bytes" "bytes"
"errors" "errors"
"fmt" "fmt"
"github.com/fatih/color"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/log"
m "github.com/grafana/grafana/pkg/cmd/grafana-cli/models"
s "github.com/grafana/grafana/pkg/cmd/grafana-cli/services"
"io" "io"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
...@@ -16,6 +12,11 @@ import ( ...@@ -16,6 +12,11 @@ import (
"path" "path"
"regexp" "regexp"
"strings" "strings"
"github.com/fatih/color"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/log"
m "github.com/grafana/grafana/pkg/cmd/grafana-cli/models"
s "github.com/grafana/grafana/pkg/cmd/grafana-cli/services"
) )
func validateInput(c CommandLine, pluginFolder string) error { func validateInput(c CommandLine, pluginFolder string) error {
...@@ -24,17 +25,16 @@ func validateInput(c CommandLine, pluginFolder string) error { ...@@ -24,17 +25,16 @@ func validateInput(c CommandLine, pluginFolder string) error {
return errors.New("please specify plugin to install") return errors.New("please specify plugin to install")
} }
pluginDir := c.GlobalString("path") pluginsDir := c.GlobalString("pluginsDir")
if pluginDir == "" { if pluginsDir == "" {
return errors.New("missing path flag") return errors.New("missing pluginsDir flag")
} }
fileInfo, err := os.Stat(pluginDir) fileInfo, err := os.Stat(pluginsDir)
if err != nil { if err != nil {
if err = os.MkdirAll(pluginDir, os.ModePerm); err != nil { if err = os.MkdirAll(pluginsDir, os.ModePerm); err != nil {
return errors.New("path is not a directory") return errors.New(fmt.Sprintf("pluginsDir (%s) is not a directory", pluginsDir))
} }
return nil return nil
} }
...@@ -46,7 +46,7 @@ func validateInput(c CommandLine, pluginFolder string) error { ...@@ -46,7 +46,7 @@ func validateInput(c CommandLine, pluginFolder string) error {
} }
func installCommand(c CommandLine) error { func installCommand(c CommandLine) error {
pluginFolder := c.GlobalString("path") pluginFolder := c.GlobalString("pluginsDir")
if err := validateInput(c, pluginFolder); err != nil { if err := validateInput(c, pluginFolder); err != nil {
return err return err
} }
...@@ -59,7 +59,7 @@ func installCommand(c CommandLine) error { ...@@ -59,7 +59,7 @@ func installCommand(c CommandLine) error {
func InstallPlugin(pluginName, version string, c CommandLine) error { func InstallPlugin(pluginName, version string, c CommandLine) error {
plugin, err := s.GetPlugin(pluginName, c.GlobalString("repo")) plugin, err := s.GetPlugin(pluginName, c.GlobalString("repo"))
pluginFolder := c.GlobalString("path") pluginFolder := c.GlobalString("pluginsDir")
if err != nil { if err != nil {
return err return err
} }
......
...@@ -3,6 +3,7 @@ package commands ...@@ -3,6 +3,7 @@ package commands
import ( import (
"errors" "errors"
"fmt" "fmt"
"github.com/fatih/color" "github.com/fatih/color"
"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"
...@@ -31,7 +32,7 @@ var validateLsCommand = func(pluginDir string) error { ...@@ -31,7 +32,7 @@ var validateLsCommand = func(pluginDir string) error {
} }
func lsCommand(c CommandLine) error { func lsCommand(c CommandLine) error {
pluginDir := c.GlobalString("path") pluginDir := c.GlobalString("pluginsDir")
if err := validateLsCommand(pluginDir); err != nil { if err := validateLsCommand(pluginDir); err != nil {
return err return err
} }
......
...@@ -2,6 +2,7 @@ package commands ...@@ -2,6 +2,7 @@ package commands
import ( 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" services "github.com/grafana/grafana/pkg/cmd/grafana-cli/services"
...@@ -11,7 +12,7 @@ var getPluginss func(path string) []m.InstalledPlugin = services.GetLocalPlugins ...@@ -11,7 +12,7 @@ var getPluginss func(path string) []m.InstalledPlugin = services.GetLocalPlugins
var removePlugin func(pluginPath, id string) error = services.RemoveInstalledPlugin var removePlugin func(pluginPath, id string) error = services.RemoveInstalledPlugin
func removeCommand(c CommandLine) error { func removeCommand(c CommandLine) error {
pluginPath := c.GlobalString("path") pluginPath := c.GlobalString("pluginsDir")
localPlugins := getPluginss(pluginPath) localPlugins := getPluginss(pluginPath)
log.Info("remove!\n") log.Info("remove!\n")
......
...@@ -28,9 +28,9 @@ func ShouldUpgrade(installed string, remote m.Plugin) bool { ...@@ -28,9 +28,9 @@ func ShouldUpgrade(installed string, remote m.Plugin) bool {
} }
func upgradeAllCommand(c CommandLine) error { func upgradeAllCommand(c CommandLine) error {
pluginDir := c.GlobalString("path") pluginsDir := c.GlobalString("pluginsDir")
localPlugins := s.GetLocalPlugins(pluginDir) localPlugins := s.GetLocalPlugins(pluginsDir)
remotePlugins, err := s.ListAllPlugins(c.GlobalString("repo")) remotePlugins, err := s.ListAllPlugins(c.GlobalString("repo"))
...@@ -53,7 +53,7 @@ func upgradeAllCommand(c CommandLine) error { ...@@ -53,7 +53,7 @@ func upgradeAllCommand(c CommandLine) error {
for _, p := range pluginsToUpgrade { for _, p := range pluginsToUpgrade {
log.Infof("Upgrading %v \n", p.Id) log.Infof("Upgrading %v \n", p.Id)
s.RemoveInstalledPlugin(pluginDir, p.Id) s.RemoveInstalledPlugin(pluginsDir, p.Id)
InstallPlugin(p.Id, "", c) InstallPlugin(p.Id, "", c)
} }
......
...@@ -5,10 +5,10 @@ import ( ...@@ -5,10 +5,10 @@ import (
) )
func upgradeCommand(c CommandLine) error { func upgradeCommand(c CommandLine) error {
pluginDir := c.GlobalString("path") pluginsDir := c.GlobalString("pluginsDir")
pluginName := c.Args().First() pluginName := c.Args().First()
localPlugin, err := s.ReadPlugin(pluginDir, pluginName) localPlugin, err := s.ReadPlugin(pluginsDir, pluginName)
if err != nil { if err != nil {
return err return err
...@@ -23,7 +23,7 @@ func upgradeCommand(c CommandLine) error { ...@@ -23,7 +23,7 @@ func upgradeCommand(c CommandLine) error {
for _, v := range remotePlugins.Plugins { for _, v := range remotePlugins.Plugins {
if localPlugin.Id == v.Id { if localPlugin.Id == v.Id {
if ShouldUpgrade(localPlugin.Info.Version, v) { if ShouldUpgrade(localPlugin.Info.Version, v) {
s.RemoveInstalledPlugin(pluginDir, pluginName) s.RemoveInstalledPlugin(pluginsDir, pluginName)
return InstallPlugin(localPlugin.Id, "", c) return InstallPlugin(localPlugin.Id, "", c)
} }
} }
......
...@@ -2,16 +2,17 @@ package main ...@@ -2,16 +2,17 @@ package main
import ( import (
"fmt" "fmt"
"os"
"runtime"
"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"
"os"
"runtime"
) )
var version = "master" var version = "master"
func getGrafanaPluginPath() string { func getGrafanaPluginDir() string {
os := runtime.GOOS os := runtime.GOOS
if os == "windows" { if os == "windows" {
return "C:\\opt\\grafana\\plugins" return "C:\\opt\\grafana\\plugins"
...@@ -25,14 +26,15 @@ func main() { ...@@ -25,14 +26,15 @@ func main() {
app := cli.NewApp() app := cli.NewApp()
app.Name = "Grafana cli" app.Name = "Grafana cli"
app.Author = "raintank" app.Usage = ""
app.Author = "Grafana Project"
app.Email = "https://github.com/grafana/grafana" app.Email = "https://github.com/grafana/grafana"
app.Version = version app.Version = version
app.Flags = []cli.Flag{ app.Flags = []cli.Flag{
cli.StringFlag{ cli.StringFlag{
Name: "path", Name: "pluginsDir",
Usage: "path to the grafana installation", Usage: "path to the grafana plugin directory",
Value: getGrafanaPluginPath(), Value: getGrafanaPluginDir(),
EnvVar: "GF_PLUGIN_DIR", EnvVar: "GF_PLUGIN_DIR",
}, },
cli.StringFlag{ cli.StringFlag{
......
...@@ -4,10 +4,11 @@ import ( ...@@ -4,10 +4,11 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"path"
"github.com/franela/goreq" "github.com/franela/goreq"
"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"
"path"
) )
var IoHelper m.IoUtil = IoUtilImp{} var IoHelper m.IoUtil = IoUtilImp{}
...@@ -66,9 +67,7 @@ func RemoveInstalledPlugin(pluginPath, id string) error { ...@@ -66,9 +67,7 @@ func RemoveInstalledPlugin(pluginPath, id string) error {
} }
func GetPlugin(pluginId, repoUrl string) (m.Plugin, error) { func GetPlugin(pluginId, repoUrl string) (m.Plugin, error) {
resp, err := ListAllPlugins(repoUrl) resp, _ := ListAllPlugins(repoUrl)
if err != nil {
}
for _, i := range resp.Plugins { for _, i := range resp.Plugins {
if i.Id == pluginId { if i.Id == pluginId {
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
<a href="{{ctrl.titleUrl}}" class="navbar-page-btn" ng-show="ctrl.title"> <a href="{{ctrl.titleUrl}}" class="navbar-page-btn" ng-show="ctrl.title">
<i class="{{ctrl.icon}}" ng-show="ctrl.icon"></i> <i class="{{ctrl.icon}}" ng-show="ctrl.icon"></i>
<img src="{{ctrl.iconUrl}}" ng-show="ctrl.iconUrl"></i> <img ng-src="{{ctrl.iconUrl}}" ng-show="ctrl.iconUrl"></i>
{{ctrl.title}} {{ctrl.title}}
</a> </a>
......
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