Updated tests and add new functions for versioning

Signed-off-by: Mihael Rodek <mihael.rodek1@gmail.com>
pull/10971/head
Mihael Rodek 3 years ago
parent 7a9d79f99b
commit ad9c68dc19

@ -29,8 +29,7 @@ import (
)
type pluginUpdateOptions struct {
names map[string]string
version string
names map[string]string
}
const pluginUpdateDesc = `
@ -41,7 +40,7 @@ func newPluginUpdateCmd(out io.Writer) *cobra.Command {
o := &pluginUpdateOptions{}
cmd := &cobra.Command{
Use: "update <plugin:[version]>...",
Use: "update <plugin[:version]>...",
Aliases: []string{"up"},
Short: "update one or more Helm plugins",
Long: pluginUpdateDesc,
@ -55,7 +54,6 @@ func newPluginUpdateCmd(out io.Writer) *cobra.Command {
return o.run(out)
},
}
cmd.Flags().StringVar(&o.version, "version", "", "specify a version constraint. If this is not specified, the latest version is installed")
return cmd
}
@ -109,7 +107,13 @@ func updatePlugin(p *plugin.Plugin, version string) error {
return err
}
i, err := installer.FindSource(absExactLocation, version)
var i installer.Installer
if version != "" {
i, err = installer.FindSourceWithVersion(absExactLocation, version)
} else {
i, err = installer.FindSource(absExactLocation)
}
if err != nil {
return err
}

@ -75,8 +75,17 @@ func NewForSource(source, version string) (Installer, error) {
}
// FindSource determines the correct Installer for the given source.
func FindSource(location, version string) (Installer, error) {
installer, err := existingVCSRepo(location, version)
func FindSource(location string) (Installer, error) {
installer, err := existingVCSRepo(location)
if err != nil && err.Error() == "Cannot detect VCS" {
return installer, errors.New("cannot get information about plugin source")
}
return installer, err
}
// FindSourceWithVersion determines the correct Installer for the given source with provided version.
func FindSourceWithVersion(location, version string) (Installer, error) {
installer, err := existingVCSRepoWithVersion(location, version)
if err != nil && err.Error() == "Cannot detect VCS" {
return installer, errors.New("cannot get information about plugin source")
}

@ -16,11 +16,11 @@ limitations under the License.
package installer // import "helm.sh/helm/v3/pkg/plugin/installer"
import (
"github.com/Masterminds/vcs"
"os"
"sort"
"github.com/Masterminds/semver/v3"
"github.com/Masterminds/vcs"
"github.com/pkg/errors"
"helm.sh/helm/v3/internal/third_party/dep/fs"
@ -35,7 +35,19 @@ type VCSInstaller struct {
base
}
func existingVCSRepo(location, version string) (Installer, error) {
func existingVCSRepo(location string) (Installer, error) {
repo, err := vcs.NewRepo("", location)
if err != nil {
return nil, err
}
i := &VCSInstaller{
Repo: repo,
base: newBase(repo.Remote()),
}
return i, nil
}
func existingVCSRepoWithVersion(location, version string) (Installer, error) {
repo, err := vcs.NewRepo("", location)
if err != nil {
return nil, err

Loading…
Cancel
Save