From 430709170a94ac754faf936d67121c1d69a30f0e Mon Sep 17 00:00:00 2001 From: Marc Khouzam Date: Thu, 27 Aug 2020 22:26:40 -0400 Subject: [PATCH] feat(comp): Add descriptions for --version comp Ref: HIP 0008 When completing a version, extra information will be shown for shells that support completions (fish, zsh). For example: $ helm upgrade nginx stable/grafana --version 0.8.4 -- Created: March 30, 2018 0.8.5 -- App: 5.0.4, Created: April 10, 2018 1.0.0 -- App: 5.0.4, Created: April 11, 2018 (deprecated) 1.10.0 -- App: 5.1.2, Created: June 1, 2018 Signed-off-by: Marc Khouzam --- cmd/helm/flags.go | 16 +++++++++++++++- .../helmhome/helm/repository/testing-index.yaml | 5 +++++ cmd/helm/testdata/output/version-comp.txt | 6 +++--- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/cmd/helm/flags.go b/cmd/helm/flags.go index 5b0288632..92857a817 100644 --- a/cmd/helm/flags.go +++ b/cmd/helm/flags.go @@ -150,7 +150,21 @@ func compVersionFlag(chartRef string, toComplete string) ([]string, cobra.ShellC for _, details := range indexFile.Entries[chartName] { version := details.Metadata.Version if strings.HasPrefix(version, toComplete) { - versions = append(versions, version) + appVersion := details.Metadata.AppVersion + appVersionDesc := "" + if appVersion != "" { + appVersionDesc = fmt.Sprintf("App: %s, ", appVersion) + } + created := details.Created.Format("January 2, 2006") + createdDesc := "" + if created != "" { + createdDesc = fmt.Sprintf("Created: %s ", created) + } + deprecated := "" + if details.Metadata.Deprecated { + deprecated = "(deprecated)" + } + versions = append(versions, fmt.Sprintf("%s\t%s%s%s", version, appVersionDesc, createdDesc, deprecated)) } } } diff --git a/cmd/helm/testdata/helmhome/helm/repository/testing-index.yaml b/cmd/helm/testdata/helmhome/helm/repository/testing-index.yaml index 889d7d87a..91e4d463f 100644 --- a/cmd/helm/testdata/helmhome/helm/repository/testing-index.yaml +++ b/cmd/helm/testdata/helmhome/helm/repository/testing-index.yaml @@ -4,6 +4,8 @@ entries: - name: alpine url: https://charts.helm.sh/stable/alpine-0.1.0.tgz checksum: 0e6661f193211d7a5206918d42f5c2a9470b737d + created: "2018-06-27T10:00:18.230700509Z" + deprecated: true home: https://helm.sh/helm sources: - https://github.com/helm/helm @@ -17,6 +19,7 @@ entries: - name: alpine url: https://charts.helm.sh/stable/alpine-0.2.0.tgz checksum: 0e6661f193211d7a5206918d42f5c2a9470b737d + created: "2018-07-09T11:34:37.797864902Z" home: https://helm.sh/helm sources: - https://github.com/helm/helm @@ -30,6 +33,7 @@ entries: - name: alpine url: https://charts.helm.sh/stable/alpine-0.3.0-rc.1.tgz checksum: 0e6661f193211d7a5206918d42f5c2a9470b737d + created: "2020-11-12T08:44:58.872726222Z" home: https://helm.sh/helm sources: - https://github.com/helm/helm @@ -44,6 +48,7 @@ entries: - name: mariadb url: https://charts.helm.sh/stable/mariadb-0.3.0.tgz checksum: 65229f6de44a2be9f215d11dbff311673fc8ba56 + created: "2018-04-23T08:20:27.160959131Z" home: https://mariadb.org sources: - https://github.com/bitnami/bitnami-docker-mariadb diff --git a/cmd/helm/testdata/output/version-comp.txt b/cmd/helm/testdata/output/version-comp.txt index 098e2cec2..5b0556cf5 100644 --- a/cmd/helm/testdata/output/version-comp.txt +++ b/cmd/helm/testdata/output/version-comp.txt @@ -1,5 +1,5 @@ -0.3.0-rc.1 -0.2.0 -0.1.0 +0.3.0-rc.1 App: 3.0.0, Created: November 12, 2020 +0.2.0 App: 2.3.4, Created: July 9, 2018 +0.1.0 App: 1.2.3, Created: June 27, 2018 (deprecated) :4 Completion ended with directive: ShellCompDirectiveNoFileComp