From f6c5242a93d233a02ece73aaa35f79efe36fadd5 Mon Sep 17 00:00:00 2001 From: bergquist Date: Mon, 7 Mar 2016 13:27:51 +0100 Subject: [PATCH] feat(cli): make repo url a parameter this is a quick hack to support repo url as parameter. Will refactor later --- pkg/cmd/grafana-cli/commands/install_command.go | 8 ++++---- pkg/cmd/grafana-cli/commands/listremote_command.go | 2 +- pkg/cmd/grafana-cli/commands/upgrade_all_command.go | 4 ++-- pkg/cmd/grafana-cli/commands/upgrade_command.go | 4 ++-- pkg/cmd/grafana-cli/main.go | 5 +++++ pkg/cmd/grafana-cli/services/services.go | 12 ++++++------ 6 files changed, 20 insertions(+), 15 deletions(-) diff --git a/pkg/cmd/grafana-cli/commands/install_command.go b/pkg/cmd/grafana-cli/commands/install_command.go index 1d085cad89e..181b899554b 100644 --- a/pkg/cmd/grafana-cli/commands/install_command.go +++ b/pkg/cmd/grafana-cli/commands/install_command.go @@ -45,11 +45,11 @@ func installCommand(c CommandLine) error { log.Infof("version: %v\n", version) - return InstallPlugin(pluginToInstall, pluginFolder, version) + return InstallPlugin(pluginToInstall, pluginFolder, version, c.GlobalString("repo")) } -func InstallPlugin(pluginName, pluginFolder, version string) error { - plugin, err := s.GetPlugin(pluginName) +func InstallPlugin(pluginName, pluginFolder, version, repoUrl string) error { + plugin, err := s.GetPlugin(pluginName, repoUrl) if err != nil { return err } @@ -77,7 +77,7 @@ func InstallPlugin(pluginName, pluginFolder, version string) error { res, _ := s.ReadPlugin(pluginFolder, pluginName) for _, v := range res.Dependency.Plugins { - InstallPlugin(v.Id, pluginFolder, "") + InstallPlugin(v.Id, pluginFolder, "", repoUrl) log.Infof("Installed Dependency: %v ✔\n", v.Id) } diff --git a/pkg/cmd/grafana-cli/commands/listremote_command.go b/pkg/cmd/grafana-cli/commands/listremote_command.go index 7cb3d650c55..0f0c3077ab9 100644 --- a/pkg/cmd/grafana-cli/commands/listremote_command.go +++ b/pkg/cmd/grafana-cli/commands/listremote_command.go @@ -6,7 +6,7 @@ import ( ) func listremoteCommand(c CommandLine) error { - plugin, err := s.ListAllPlugins() + plugin, err := s.ListAllPlugins(c.GlobalString("repo")) if err != nil { return err diff --git a/pkg/cmd/grafana-cli/commands/upgrade_all_command.go b/pkg/cmd/grafana-cli/commands/upgrade_all_command.go index 6c1e0182f51..0bb89866fcd 100644 --- a/pkg/cmd/grafana-cli/commands/upgrade_all_command.go +++ b/pkg/cmd/grafana-cli/commands/upgrade_all_command.go @@ -32,7 +32,7 @@ func upgradeAllCommand(c CommandLine) error { localPlugins := s.GetLocalPlugins(pluginDir) - remotePlugins, err := s.ListAllPlugins() + remotePlugins, err := s.ListAllPlugins(c.GlobalString("repo")) if err != nil { return err @@ -54,7 +54,7 @@ func upgradeAllCommand(c CommandLine) error { log.Infof("Upgrading %v \n", p.Id) s.RemoveInstalledPlugin(pluginDir, p.Id) - InstallPlugin(p.Id, pluginDir, "") + InstallPlugin(p.Id, pluginDir, "", c.GlobalString("repo")) } return nil diff --git a/pkg/cmd/grafana-cli/commands/upgrade_command.go b/pkg/cmd/grafana-cli/commands/upgrade_command.go index 5a4fe477c9b..c3d2cf06aea 100644 --- a/pkg/cmd/grafana-cli/commands/upgrade_command.go +++ b/pkg/cmd/grafana-cli/commands/upgrade_command.go @@ -14,7 +14,7 @@ func upgradeCommand(c CommandLine) error { return err } - remotePlugins, err2 := s.ListAllPlugins() + remotePlugins, err2 := s.ListAllPlugins(c.GlobalString("repo")) if err2 != nil { return err2 @@ -24,7 +24,7 @@ func upgradeCommand(c CommandLine) error { if localPlugin.Id == v.Id { if ShouldUpgrade(localPlugin.Info.Version, v) { s.RemoveInstalledPlugin(pluginDir, pluginName) - return InstallPlugin(localPlugin.Id, pluginDir, "") + return InstallPlugin(localPlugin.Id, pluginDir, "", c.GlobalString("repo")) } } } diff --git a/pkg/cmd/grafana-cli/main.go b/pkg/cmd/grafana-cli/main.go index 938cfcc284a..8c2b0b9c53d 100644 --- a/pkg/cmd/grafana-cli/main.go +++ b/pkg/cmd/grafana-cli/main.go @@ -36,6 +36,11 @@ func main() { Usage: "path to the grafana installation", Value: getGrafanaPluginPath(), }, + cli.StringFlag{ + Name: "repo", + Usage: "url to the plugin repository", + Value: "https://raw.githubusercontent.com/grafana/grafana-plugin-repository/master/repo.json", + }, cli.BoolFlag{ Name: "debug, d", Usage: "enable debug logging", diff --git a/pkg/cmd/grafana-cli/services/services.go b/pkg/cmd/grafana-cli/services/services.go index d5051a623a3..c23c716b62f 100644 --- a/pkg/cmd/grafana-cli/services/services.go +++ b/pkg/cmd/grafana-cli/services/services.go @@ -11,8 +11,8 @@ import ( var IoHelper m.IoUtil = IoUtilImp{} -func ListAllPlugins() (m.PluginRepo, error) { - res, _ := goreq.Request{Uri: "https://raw.githubusercontent.com/grafana/grafana-plugin-repository/master/repo.json"}.Do() +func ListAllPlugins(repoUrl string) (m.PluginRepo, error) { + res, _ := goreq.Request{Uri: repoUrl}.Do() var resp m.PluginRepo err := res.Body.FromJsonTo(&resp) @@ -59,16 +59,16 @@ func RemoveInstalledPlugin(pluginPath, id string) error { return IoHelper.RemoveAll(path.Join(pluginPath, id)) } -func GetPlugin(id string) (m.Plugin, error) { - resp, err := ListAllPlugins() +func GetPlugin(pluginId, repoUrl string) (m.Plugin, error) { + resp, err := ListAllPlugins(repoUrl) if err != nil { } for _, i := range resp.Plugins { - if i.Id == id { + if i.Id == pluginId { return i, nil } } - return m.Plugin{}, errors.New("could not find plugin named \"" + id + "\"") + return m.Plugin{}, errors.New("could not find plugin named \"" + pluginId + "\"") }