Commit 766d8a58 by Carl Bergquist Committed by GitHub

avoid aliased import in cli (#22566)

parent 3fdd2648
......@@ -20,8 +20,8 @@ import (
"golang.org/x/xerrors"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/logger"
m "github.com/grafana/grafana/pkg/cmd/grafana-cli/models"
s "github.com/grafana/grafana/pkg/cmd/grafana-cli/services"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/models"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/services"
)
func validateInput(c utils.CommandLine, pluginFolder string) error {
......@@ -132,7 +132,7 @@ func InstallPlugin(pluginName, version string, c utils.CommandLine, client utils
logger.Infof("%s Installed %s successfully \n", color.GreenString("✔"), pluginName)
res, _ := s.ReadPlugin(pluginFolder, pluginName)
res, _ := services.ReadPlugin(pluginFolder, pluginName)
for _, v := range res.Dependencies.Plugins {
if err := InstallPlugin(v.Id, "", c, client); err != nil {
return errutil.Wrapf(err, "failed to install plugin '%s'", v.Id)
......@@ -150,7 +150,7 @@ func osAndArchString() string {
return osString + "-" + arch
}
func supportsCurrentArch(version *m.Version) bool {
func supportsCurrentArch(version *models.Version) bool {
if version.Arch == nil {
return true
}
......@@ -162,7 +162,7 @@ func supportsCurrentArch(version *m.Version) bool {
return false
}
func latestSupportedVersion(plugin *m.Plugin) *m.Version {
func latestSupportedVersion(plugin *models.Plugin) *models.Version {
for _, ver := range plugin.Versions {
if supportsCurrentArch(&ver) {
return &ver
......@@ -174,8 +174,8 @@ func latestSupportedVersion(plugin *m.Plugin) *m.Version {
// SelectVersion returns latest version if none is specified or the specified version. If the version string is not
// matched to existing version it errors out. It also errors out if version that is matched is not available for current
// os and platform. It expects plugin.Versions to be sorted so the newest version is first.
func SelectVersion(plugin *m.Plugin, version string) (*m.Version, error) {
var ver m.Version
func SelectVersion(plugin *models.Plugin, version string) (*models.Version, error) {
var ver models.Version
latestForArch := latestSupportedVersion(plugin)
if latestForArch == nil {
......
......@@ -5,12 +5,12 @@ import (
"github.com/fatih/color"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/logger"
m "github.com/grafana/grafana/pkg/cmd/grafana-cli/models"
s "github.com/grafana/grafana/pkg/cmd/grafana-cli/services"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/models"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/services"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/utils"
)
var ls_getPlugins func(path string) []m.InstalledPlugin = s.GetLocalPlugins
var ls_getPlugins func(path string) []models.InstalledPlugin = services.GetLocalPlugins
var validateLsCommand = func(pluginDir string) error {
if pluginDir == "" {
......@@ -18,7 +18,7 @@ var validateLsCommand = func(pluginDir string) error {
}
logger.Debug("plugindir: " + pluginDir + "\n")
pluginDirInfo, err := s.IoHelper.Stat(pluginDir)
pluginDirInfo, err := services.IoHelper.Stat(pluginDir)
if err != nil {
return err
}
......
......@@ -2,10 +2,11 @@ package commands
import (
"errors"
"testing"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/commands/commandstest"
s "github.com/grafana/grafana/pkg/cmd/grafana-cli/services"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/services"
. "github.com/smartystreets/goconvey/convey"
"testing"
)
func TestMissingPath(t *testing.T) {
......@@ -18,7 +19,7 @@ func TestMissingPath(t *testing.T) {
cmd := Command{}
c, err := commandstest.NewCliContext(map[string]string{})
So(err, ShouldBeNil)
s.IoHelper = &commandstest.FakeIoUtil{}
services.IoHelper = &commandstest.FakeIoUtil{}
Convey("should return error", func() {
err := cmd.lsCommand(c)
......@@ -29,7 +30,7 @@ func TestMissingPath(t *testing.T) {
Convey("Path is not a directory", func() {
c, err := commandstest.NewCliContext(map[string]string{"path": "/var/lib/grafana/plugins"})
So(err, ShouldBeNil)
s.IoHelper = &commandstest.FakeIoUtil{
services.IoHelper = &commandstest.FakeIoUtil{
FakeIsDirectory: false,
}
cmd := Command{}
......
......@@ -2,13 +2,13 @@ package commands
import (
"github.com/grafana/grafana/pkg/cmd/grafana-cli/logger"
m "github.com/grafana/grafana/pkg/cmd/grafana-cli/models"
s "github.com/grafana/grafana/pkg/cmd/grafana-cli/services"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/models"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/services"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/utils"
"github.com/hashicorp/go-version"
)
func shouldUpgrade(installed string, remote *m.Plugin) bool {
func shouldUpgrade(installed string, remote *models.Plugin) bool {
installedVersion, err := version.NewVersion(installed)
if err != nil {
return false
......@@ -25,14 +25,14 @@ func shouldUpgrade(installed string, remote *m.Plugin) bool {
func (cmd Command) upgradeAllCommand(c utils.CommandLine) error {
pluginsDir := c.PluginDirectory()
localPlugins := s.GetLocalPlugins(pluginsDir)
localPlugins := services.GetLocalPlugins(pluginsDir)
remotePlugins, err := cmd.Client.ListAllPlugins(c.String("repo"))
if err != nil {
return err
}
pluginsToUpgrade := make([]m.InstalledPlugin, 0)
pluginsToUpgrade := make([]models.InstalledPlugin, 0)
for _, localPlugin := range localPlugins {
for _, remotePlugin := range remotePlugins.Plugins {
......@@ -47,7 +47,7 @@ func (cmd Command) upgradeAllCommand(c utils.CommandLine) error {
for _, p := range pluginsToUpgrade {
logger.Infof("Updating %v \n", p.Id)
err := s.RemoveInstalledPlugin(pluginsDir, p.Id)
err := services.RemoveInstalledPlugin(pluginsDir, p.Id)
if err != nil {
return err
}
......
......@@ -3,7 +3,7 @@ package commands
import (
"github.com/fatih/color"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/logger"
s "github.com/grafana/grafana/pkg/cmd/grafana-cli/services"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/services"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/utils"
"github.com/grafana/grafana/pkg/util/errutil"
)
......@@ -12,7 +12,7 @@ func (cmd Command) upgradeCommand(c utils.CommandLine) error {
pluginsDir := c.PluginDirectory()
pluginName := c.Args().First()
localPlugin, err := s.ReadPlugin(pluginsDir, pluginName)
localPlugin, err := services.ReadPlugin(pluginsDir, pluginName)
if err != nil {
return err
......@@ -24,7 +24,7 @@ func (cmd Command) upgradeCommand(c utils.CommandLine) error {
}
if shouldUpgrade(localPlugin.Info.Version, &plugin) {
if err := s.RemoveInstalledPlugin(pluginsDir, pluginName); err != nil {
if err := services.RemoveInstalledPlugin(pluginsDir, pluginName); err != nil {
return errutil.Wrapf(err, "failed to remove plugin '%s'", pluginName)
}
......
......@@ -11,11 +11,11 @@ import (
"time"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/logger"
m "github.com/grafana/grafana/pkg/cmd/grafana-cli/models"
"github.com/grafana/grafana/pkg/cmd/grafana-cli/models"
)
var (
IoHelper m.IoUtil = IoUtilImp{}
IoHelper models.IoUtil = IoUtilImp{}
HttpClient http.Client
HttpClientNoTimeout http.Client
grafanaVersion string
......@@ -63,7 +63,7 @@ func makeHttpClient(skipTLSVerify bool, timeout time.Duration) http.Client {
}
}
func ReadPlugin(pluginDir, pluginName string) (m.InstalledPlugin, error) {
func ReadPlugin(pluginDir, pluginName string) (models.InstalledPlugin, error) {
distPluginDataPath := path.Join(pluginDir, pluginName, "dist", "plugin.json")
var data []byte
......@@ -75,11 +75,11 @@ func ReadPlugin(pluginDir, pluginName string) (m.InstalledPlugin, error) {
data, err = IoHelper.ReadFile(pluginDataPath)
if err != nil {
return m.InstalledPlugin{}, errors.New("Could not find dist/plugin.json or plugin.json on " + pluginName + " in " + pluginDir)
return models.InstalledPlugin{}, errors.New("Could not find dist/plugin.json or plugin.json on " + pluginName + " in " + pluginDir)
}
}
res := m.InstalledPlugin{}
res := models.InstalledPlugin{}
if err := json.Unmarshal(data, &res); err != nil {
return res, err
}
......@@ -89,14 +89,14 @@ func ReadPlugin(pluginDir, pluginName string) (m.InstalledPlugin, error) {
}
if res.Id == "" {
return m.InstalledPlugin{}, errors.New("could not find plugin " + pluginName + " in " + pluginDir)
return models.InstalledPlugin{}, errors.New("could not find plugin " + pluginName + " in " + pluginDir)
}
return res, nil
}
func GetLocalPlugins(pluginDir string) []m.InstalledPlugin {
result := make([]m.InstalledPlugin, 0)
func GetLocalPlugins(pluginDir string) []models.InstalledPlugin {
result := make([]models.InstalledPlugin, 0)
files, _ := IoHelper.ReadDir(pluginDir)
for _, f := range files {
res, err := ReadPlugin(pluginDir, f.Name())
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment