瀏覽代碼

tech(cli): lets use the fact that we have a compiler

bergquist 9 年之前
父節點
當前提交
07be2c89a3

+ 11 - 0
pkg/cmd/grafana-cli/commands/command_line.go

@@ -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")
+}

+ 8 - 0
pkg/cmd/grafana-cli/commands/commandstest/fake_commandLine.go

@@ -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")
+}

+ 4 - 4
pkg/cmd/grafana-cli/commands/install_command.go

@@ -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
 	}

+ 1 - 1
pkg/cmd/grafana-cli/commands/listremote_command.go

@@ -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

+ 1 - 1
pkg/cmd/grafana-cli/commands/ls_command.go

@@ -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
 	}

+ 1 - 1
pkg/cmd/grafana-cli/commands/remove_command.go

@@ -12,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("pluginsDir")
+	pluginPath := c.PluginDirectory()
 	localPlugins := getPluginss(pluginPath)
 
 	plugin := c.Args().First()

+ 1 - 1
pkg/cmd/grafana-cli/commands/upgrade_all_command.go

@@ -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)
 

+ 2 - 2
pkg/cmd/grafana-cli/commands/upgrade_command.go

@@ -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