CLI: Fix version selection for plugin install (#19498)

This commit is contained in:
Andrej Ocenas
2019-09-30 15:34:09 +02:00
committed by GitHub
parent 93919427f8
commit 3866814ea9
2 changed files with 114 additions and 19 deletions

View File

@ -157,32 +157,34 @@ 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.
// 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
if version == "" {
ver = &plugin.Versions[0]
}
for _, v := range plugin.Versions {
if v.Version == version {
ver = &v
}
}
if ver == nil {
return nil, xerrors.New("Could not find the version you're looking for")
}
var ver m.Version
latestForArch := latestSupportedVersion(plugin)
if latestForArch == nil {
return nil, xerrors.New("Plugin is not supported on your architecture and os.")
}
if latestForArch.Version == ver.Version {
return ver, nil
if version == "" {
return latestForArch, nil
}
return nil, xerrors.Errorf("Version you want is not supported on your architecture and os. Latest suitable version is %v", latestForArch.Version)
for _, v := range plugin.Versions {
if v.Version == version {
ver = v
break
}
}
if len(ver.Version) == 0 {
return nil, xerrors.New("Could not find the version you're looking for")
}
if !supportsCurrentArch(&ver) {
return nil, xerrors.Errorf("Version you want is not supported on your architecture and os. Latest suitable version is %v", latestForArch.Version)
}
return &ver, nil
}
func RemoveGitBuildFromName(pluginName, filename string) string {