feat(cli): support for asking grafana net about plugins
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"archive/zip"
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"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"
|
||||
@@ -64,30 +65,31 @@ func InstallPlugin(pluginName, version string, c CommandLine) error {
|
||||
return err
|
||||
}
|
||||
|
||||
url := v.Url
|
||||
commit := v.Commit
|
||||
|
||||
if version == "" {
|
||||
version = v.Version
|
||||
}
|
||||
|
||||
downloadURL := url + "/archive/" + commit + ".zip"
|
||||
downloadURL := fmt.Sprintf("%s/%s/versions/%s/download",
|
||||
c.GlobalString("repo"),
|
||||
pluginName,
|
||||
version)
|
||||
|
||||
log.Infof("installing %v @ %v\n", plugin.Id, version)
|
||||
log.Infof("from url: %v\n", downloadURL)
|
||||
log.Infof("on commit: %v\n", commit)
|
||||
log.Infof("into: %v\n", pluginFolder)
|
||||
|
||||
err = downloadFile(plugin.Id, pluginFolder, downloadURL)
|
||||
if err == nil {
|
||||
log.Infof("Installed %v successfully ✔\n", plugin.Id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
log.Infof("Installed %v successfully ✔\n", plugin.Id)
|
||||
|
||||
res, _ := s.ReadPlugin(pluginFolder, pluginName)
|
||||
|
||||
for _, v := range res.Dependency.Plugins {
|
||||
InstallPlugin(v.Id, version, c)
|
||||
log.Infof("Installed Dependency: %v ✔\n", v.Id)
|
||||
log.Infof("Installed dependency: %v ✔\n", v.Id)
|
||||
}
|
||||
|
||||
return err
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
|
||||
var ls_getPlugins func(path string) []m.InstalledPlugin = s.GetLocalPlugins
|
||||
|
||||
var validateLsCommmand = func(pluginDir string) error {
|
||||
var validateLsCommand = func(pluginDir string) error {
|
||||
if pluginDir == "" {
|
||||
return errors.New("missing path flag")
|
||||
}
|
||||
@@ -31,7 +31,7 @@ var validateLsCommmand = func(pluginDir string) error {
|
||||
|
||||
func lsCommand(c CommandLine) error {
|
||||
pluginDir := c.GlobalString("path")
|
||||
if err := validateLsCommmand(pluginDir); err != nil {
|
||||
if err := validateLsCommand(pluginDir); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -9,10 +9,10 @@ import (
|
||||
)
|
||||
|
||||
func TestMissingPath(t *testing.T) {
|
||||
var org = validateLsCommmand
|
||||
var org = validateLsCommand
|
||||
|
||||
Convey("ls command", t, func() {
|
||||
validateLsCommmand = org
|
||||
validateLsCommand = org
|
||||
|
||||
Convey("Missing path", func() {
|
||||
commandLine := &commandstest.FakeCommandLine{
|
||||
@@ -61,7 +61,7 @@ func TestMissingPath(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
validateLsCommmand = func(pluginDir string) error {
|
||||
validateLsCommand = func(pluginDir string) error {
|
||||
return errors.New("dummie error")
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user