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

This commit is contained in:
bergquist 2016-06-24 20:14:58 +02:00
parent 88e208bddf
commit 07be2c89a3
8 changed files with 29 additions and 10 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

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

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