mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
tech(cli): lets use the fact that we have a compiler
This commit is contained in:
parent
88e208bddf
commit
07be2c89a3
@ -16,6 +16,9 @@ type CommandLine interface {
|
|||||||
GlobalString(name string) string
|
GlobalString(name string) string
|
||||||
FlagNames() (names []string)
|
FlagNames() (names []string)
|
||||||
Generic(name string) interface{}
|
Generic(name string) interface{}
|
||||||
|
|
||||||
|
PluginDirectory() string
|
||||||
|
RepoDirectory() string
|
||||||
}
|
}
|
||||||
|
|
||||||
type contextCommandLine struct {
|
type contextCommandLine struct {
|
||||||
@ -33,3 +36,11 @@ func (c *contextCommandLine) ShowVersion() {
|
|||||||
func (c *contextCommandLine) Application() *cli.App {
|
func (c *contextCommandLine) Application() *cli.App {
|
||||||
return c.App
|
return c.App
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *contextCommandLine) PluginDirectory() string {
|
||||||
|
return c.GlobalString("pluginsDir")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *contextCommandLine) RepoDirectory() string {
|
||||||
|
return c.GlobalString("repo")
|
||||||
|
}
|
||||||
|
@ -93,3 +93,11 @@ func (fcli *FakeCommandLine) Args() cli.Args {
|
|||||||
func (fcli *FakeCommandLine) ShowVersion() {
|
func (fcli *FakeCommandLine) ShowVersion() {
|
||||||
fcli.VersionShown = true
|
fcli.VersionShown = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (fcli *FakeCommandLine) RepoDirectory() string {
|
||||||
|
return fcli.GlobalString("repo")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fcli *FakeCommandLine) PluginDirectory() string {
|
||||||
|
return fcli.GlobalString("pluginsDir")
|
||||||
|
}
|
||||||
|
@ -25,7 +25,7 @@ func validateInput(c CommandLine, pluginFolder string) error {
|
|||||||
return errors.New("please specify plugin to install")
|
return errors.New("please specify plugin to install")
|
||||||
}
|
}
|
||||||
|
|
||||||
pluginsDir := c.GlobalString("pluginsDir")
|
pluginsDir := c.PluginDirectory()
|
||||||
if pluginsDir == "" {
|
if pluginsDir == "" {
|
||||||
return errors.New("missing pluginsDir flag")
|
return errors.New("missing pluginsDir flag")
|
||||||
}
|
}
|
||||||
@ -46,7 +46,7 @@ func validateInput(c CommandLine, pluginFolder string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func installCommand(c CommandLine) error {
|
func installCommand(c CommandLine) error {
|
||||||
pluginFolder := c.GlobalString("pluginsDir")
|
pluginFolder := c.PluginDirectory()
|
||||||
if err := validateInput(c, pluginFolder); err != nil {
|
if err := validateInput(c, pluginFolder); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -58,8 +58,8 @@ func installCommand(c CommandLine) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func InstallPlugin(pluginName, version string, c CommandLine) error {
|
func InstallPlugin(pluginName, version string, c CommandLine) error {
|
||||||
plugin, err := s.GetPlugin(pluginName, c.GlobalString("repo"))
|
plugin, err := s.GetPlugin(pluginName, c.RepoDirectory())
|
||||||
pluginFolder := c.GlobalString("pluginsDir")
|
pluginFolder := c.PluginDirectory()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func listremoteCommand(c CommandLine) error {
|
func listremoteCommand(c CommandLine) error {
|
||||||
plugin, err := s.ListAllPlugins(c.GlobalString("repo"))
|
plugin, err := s.ListAllPlugins(c.RepoDirectory())
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -32,7 +32,7 @@ var validateLsCommand = func(pluginDir string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func lsCommand(c CommandLine) error {
|
func lsCommand(c CommandLine) error {
|
||||||
pluginDir := c.GlobalString("pluginsDir")
|
pluginDir := c.PluginDirectory()
|
||||||
if err := validateLsCommand(pluginDir); err != nil {
|
if err := validateLsCommand(pluginDir); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ var getPluginss func(path string) []m.InstalledPlugin = services.GetLocalPlugins
|
|||||||
var removePlugin func(pluginPath, id string) error = services.RemoveInstalledPlugin
|
var removePlugin func(pluginPath, id string) error = services.RemoveInstalledPlugin
|
||||||
|
|
||||||
func removeCommand(c CommandLine) error {
|
func removeCommand(c CommandLine) error {
|
||||||
pluginPath := c.GlobalString("pluginsDir")
|
pluginPath := c.PluginDirectory()
|
||||||
localPlugins := getPluginss(pluginPath)
|
localPlugins := getPluginss(pluginPath)
|
||||||
|
|
||||||
plugin := c.Args().First()
|
plugin := c.Args().First()
|
||||||
|
@ -28,7 +28,7 @@ func ShouldUpgrade(installed string, remote m.Plugin) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func upgradeAllCommand(c CommandLine) error {
|
func upgradeAllCommand(c CommandLine) error {
|
||||||
pluginsDir := c.GlobalString("pluginsDir")
|
pluginsDir := c.PluginDirectory()
|
||||||
|
|
||||||
localPlugins := s.GetLocalPlugins(pluginsDir)
|
localPlugins := s.GetLocalPlugins(pluginsDir)
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func upgradeCommand(c CommandLine) error {
|
func upgradeCommand(c CommandLine) error {
|
||||||
pluginsDir := c.GlobalString("pluginsDir")
|
pluginsDir := c.PluginDirectory()
|
||||||
pluginName := c.Args().First()
|
pluginName := c.Args().First()
|
||||||
|
|
||||||
localPlugin, err := s.ReadPlugin(pluginsDir, pluginName)
|
localPlugin, err := s.ReadPlugin(pluginsDir, pluginName)
|
||||||
@ -16,7 +16,7 @@ func upgradeCommand(c CommandLine) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
v, err2 := s.GetPlugin(localPlugin.Id, c.GlobalString("repo"))
|
v, err2 := s.GetPlugin(localPlugin.Id, c.RepoDirectory())
|
||||||
|
|
||||||
if err2 != nil {
|
if err2 != nil {
|
||||||
return err2
|
return err2
|
||||||
|
Loading…
Reference in New Issue
Block a user