Commit 71fa47f5 authored by Mateusz Szostok's avatar Mateusz Szostok

fix(repo/search): fix helm repo search command to display proper versions

Introduce the `--devel` flag for `helm repo search` command.

`helm repo search` - searches only for stable releases, prerelease versions will be skip
`helm repo search --devel` - searches for releases and prereleases (alpha, beta, and release candidate releases)
`helm repo search --version 1.0.0 - searches for release in version 1.0.0
Signed-off-by: 's avatarMateusz Szostok <szostok.mateusz@gmail.com>
parent 0a9bf4f9
......@@ -34,6 +34,21 @@ const searchDesc = `
Search reads through all of the repositories configured on the system, and
looks for matches.
It will display the latest stable versions of the charts found. If you
specify the --devel flag, the output will include pre-release versions.
If you want to search using a version constraint, use --version.
Examples:
# Search for stable release versions matching the keyword "nginx"
helm search nginx
# Search for release versions matching the keyword "nginx", including pre-release versions
helm search nginx --devel
# Search for the latest patch release for nginx-ingress 1.x
helm search nginx-ingress --version ^1.0.0
Repositories are managed with 'helm repo' commands.
To look for charts with a particular name (such as stable/mysql), try
......@@ -59,6 +74,7 @@ type searchCmd struct {
out io.Writer
helmhome helmpath.Home
devel bool
versions bool
regexp bool
version string
......@@ -89,6 +105,7 @@ func newSearchCmd(out io.Writer) *cobra.Command {
f := cmd.Flags()
f.BoolVarP(&sc.regexp, "regexp", "r", false, "Use regular expressions for searching")
f.BoolVarP(&sc.versions, "versions", "l", false, "Show the long listing, with each version of each chart on its own line")
f.BoolVar(&sc.devel, "devel", false, "use development versions (alpha, beta, and release candidate releases), too. Equivalent to version '>0.0.0-0'. If --version is set, this is ignored")
f.StringVarP(&sc.version, "version", "v", "", "Search using semantic versioning constraints")
f.UintVar(&sc.colWidth, "col-width", 60, "Specifies the max column width of output")
bindOutputFlag(cmd, &sc.output)
......@@ -97,6 +114,7 @@ func newSearchCmd(out io.Writer) *cobra.Command {
}
func (s *searchCmd) run(args []string) error {
s.setupSearchedVersion()
index, err := s.buildIndex()
if err != nil {
return err
......@@ -122,6 +140,22 @@ func (s *searchCmd) run(args []string) error {
return write(s.out, &searchWriter{data, s.colWidth}, outputFormat(s.output))
}
func (s *searchCmd) setupSearchedVersion() {
debug("Original chart version: %q", s.version)
if s.version != "" {
return
}
if s.devel { // search for releases and prereleases (alpha, beta, and release candidate releases).
debug("setting version to >0.0.0-0")
s.version = ">0.0.0-0"
} else { // search only for stable releases, prerelease versions will be skip
debug("setting version to >0.0.0")
s.version = ">0.0.0"
}
}
func (s *searchCmd) applyConstraint(res []*search.Result) ([]*search.Result, error) {
if len(s.version) == 0 {
return res, nil
......
......@@ -33,6 +33,12 @@ func TestSearchCmd(t *testing.T) {
args: []string{"maria"},
expected: "NAME \tCHART VERSION\tAPP VERSION\tDESCRIPTION \ntesting/mariadb\t0.3.0 \t \tChart for MariaDB",
},
{
name: "search for 'alpine' with --devel, expect one match with newest development version",
args: []string{"alpine"},
flags: []string{"--devel"},
expected: "NAME \tCHART VERSION\tAPP VERSION\tDESCRIPTION \ntesting/alpine\t0.3.0-rc.1 \t3.0.0 \tDeploy a basic Alpine Linux pod\n",
},
{
name: "search for 'alpine', expect two matches",
args: []string{"alpine"},
......
......@@ -27,6 +27,18 @@ entries:
maintainers: []
engine: ""
icon: ""
- name: alpine
url: https://kubernetes-charts.storage.googleapis.com/alpine-0.3.0-rc.1.tgz
checksum: 0e6661f193211d7a5206918d42f5c2a9470b737d
home: https://helm.sh/helm
sources:
- https://github.com/helm/helm
version: 0.3.0-rc.1
appVersion: 3.0.0
description: Deploy a basic Alpine Linux pod
keywords: []
maintainers: []
icon: ""
mariadb:
- name: mariadb
url: https://kubernetes-charts.storage.googleapis.com/mariadb-0.3.0.tgz
......
......@@ -8,6 +8,21 @@ Search for a keyword in charts
Search reads through all of the repositories configured on the system, and
looks for matches.
It will display the latest stable versions of the charts found. If you
specify the --devel flag, the output will include pre-release versions.
If you want to search using a version constraint, use --version.
Examples:
# Search for stable release versions matching the keyword "nginx"
helm search nginx
# Search for release versions matching the keyword "nginx", including pre-release versions
helm search nginx --devel
# Search for the latest patch release for nginx-ingress 1.x
helm search nginx-ingress --version ^1.0.0
Repositories are managed with 'helm repo' commands.
To look for charts with a particular name (such as stable/mysql), try
......@@ -34,6 +49,7 @@ helm search [keyword] [flags]
```
--col-width uint Specifies the max column width of output (default 60)
--devel use development versions (alpha, beta, and release candidate releases), too. Equivalent to version '>0.0.0-0'. If --version is set, this is ignored
-h, --help help for search
-o, --output string Prints the output in the specified format. Allowed values: table, json, yaml (default "table")
-r, --regexp Use regular expressions for searching
......@@ -57,4 +73,4 @@ helm search [keyword] [flags]
* [helm](helm.md) - The Helm package manager for Kubernetes.
###### Auto generated by spf13/cobra on 24-Sep-2019
###### Auto generated by spf13/cobra on 25-Oct-2019
......@@ -147,7 +147,8 @@ func (i IndexFile) SortEntries() {
// Get returns the ChartVersion for the given name.
//
// If version is empty, this will return the chart with the highest version.
// If version is empty, this will return the chart with the latest stable version,
// prerelease versions will be skipped.
func (i IndexFile) Get(name, version string) (*ChartVersion, error) {
vs, ok := i.Entries[name]
if !ok {
......
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