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