feat(grafana-cli): minor changes
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user