Merge branch 'master' into alerting

Conflicts:
	pkg/api/dashboard.go
	pkg/models/dashboards.go
	pkg/services/sqlstore/dashboard.go
This commit is contained in:
Torkel Ödegaard
2016-07-11 18:28:07 +02:00
85 changed files with 9906 additions and 1054 deletions

View File

@@ -16,6 +16,9 @@ type CommandLine interface {
GlobalString(name string) string
FlagNames() (names []string)
Generic(name string) interface{}
PluginDirectory() string
RepoDirectory() string
}
type contextCommandLine struct {
@@ -33,3 +36,11 @@ func (c *contextCommandLine) ShowVersion() {
func (c *contextCommandLine) Application() *cli.App {
return c.App
}
func (c *contextCommandLine) PluginDirectory() string {
return c.GlobalString("pluginsDir")
}
func (c *contextCommandLine) RepoDirectory() string {
return c.GlobalString("repo")
}

View File

@@ -93,3 +93,11 @@ func (fcli *FakeCommandLine) Args() cli.Args {
func (fcli *FakeCommandLine) ShowVersion() {
fcli.VersionShown = true
}
func (fcli *FakeCommandLine) RepoDirectory() string {
return fcli.GlobalString("repo")
}
func (fcli *FakeCommandLine) PluginDirectory() string {
return fcli.GlobalString("pluginsDir")
}

View File

@@ -25,7 +25,7 @@ func validateInput(c CommandLine, pluginFolder string) error {
return errors.New("please specify plugin to install")
}
pluginsDir := c.GlobalString("pluginsDir")
pluginsDir := c.PluginDirectory()
if pluginsDir == "" {
return errors.New("missing pluginsDir flag")
}
@@ -46,7 +46,7 @@ func validateInput(c CommandLine, pluginFolder string) error {
}
func installCommand(c CommandLine) error {
pluginFolder := c.GlobalString("pluginsDir")
pluginFolder := c.PluginDirectory()
if err := validateInput(c, pluginFolder); err != nil {
return err
}
@@ -58,8 +58,8 @@ func installCommand(c CommandLine) error {
}
func InstallPlugin(pluginName, version string, c CommandLine) error {
plugin, err := s.GetPlugin(pluginName, c.GlobalString("repo"))
pluginFolder := c.GlobalString("pluginsDir")
plugin, err := s.GetPlugin(pluginName, c.RepoDirectory())
pluginFolder := c.PluginDirectory()
if err != nil {
return err
}

View File

@@ -6,7 +6,7 @@ import (
)
func listremoteCommand(c CommandLine) error {
plugin, err := s.ListAllPlugins(c.GlobalString("repo"))
plugin, err := s.ListAllPlugins(c.RepoDirectory())
if err != nil {
return err

View File

@@ -32,7 +32,7 @@ var validateLsCommand = func(pluginDir string) error {
}
func lsCommand(c CommandLine) error {
pluginDir := c.GlobalString("pluginsDir")
pluginDir := c.PluginDirectory()
if err := validateLsCommand(pluginDir); err != nil {
return err
}

View File

@@ -2,30 +2,32 @@ package commands
import (
"errors"
"fmt"
m "github.com/grafana/grafana/pkg/cmd/grafana-cli/models"
services "github.com/grafana/grafana/pkg/cmd/grafana-cli/services"
"strings"
)
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("pluginsDir")
localPlugins := getPluginss(pluginPath)
pluginPath := c.PluginDirectory()
plugin := c.Args().First()
if plugin == "" {
return errors.New("Missing plugin parameter")
}
for _, p := range localPlugins {
if p.Id == c.Args().First() {
removePlugin(pluginPath, p.Id)
return nil
err := removePlugin(pluginPath, plugin)
if err != nil {
if strings.Contains(err.Error(), "no such file or directory") {
return fmt.Errorf("Plugin does not exist")
}
return err
}
return fmt.Errorf("Could not find plugin named %s", c.Args().First())
return nil
}

View File

@@ -28,7 +28,7 @@ func ShouldUpgrade(installed string, remote m.Plugin) bool {
}
func upgradeAllCommand(c CommandLine) error {
pluginsDir := c.GlobalString("pluginsDir")
pluginsDir := c.PluginDirectory()
localPlugins := s.GetLocalPlugins(pluginsDir)

View File

@@ -7,7 +7,7 @@ import (
)
func upgradeCommand(c CommandLine) error {
pluginsDir := c.GlobalString("pluginsDir")
pluginsDir := c.PluginDirectory()
pluginName := c.Args().First()
localPlugin, err := s.ReadPlugin(pluginsDir, pluginName)
@@ -16,7 +16,7 @@ func upgradeCommand(c CommandLine) error {
return err
}
v, err2 := s.GetPlugin(localPlugin.Id, c.GlobalString("repo"))
v, err2 := s.GetPlugin(localPlugin.Id, c.RepoDirectory())
if err2 != nil {
return err2

View File

@@ -75,9 +75,16 @@ func GetLocalPlugins(pluginDir string) []m.InstalledPlugin {
return result
}
func RemoveInstalledPlugin(pluginPath, id string) error {
logger.Infof("Removing plugin: %v\n", id)
return IoHelper.RemoveAll(path.Join(pluginPath, id))
func RemoveInstalledPlugin(pluginPath, pluginName string) error {
logger.Infof("Removing plugin: %v\n", pluginName)
pluginDir := path.Join(pluginPath, pluginName)
_, err := IoHelper.Stat(pluginDir)
if err != nil {
return err
}
return IoHelper.RemoveAll(pluginDir)
}
func GetPlugin(pluginId, repoUrl string) (m.Plugin, error) {