From 1d017e37933050aa398f30f70bab52135ceaad10 Mon Sep 17 00:00:00 2001 From: Marc Khouzam Date: Fri, 11 Oct 2019 19:10:57 -0400 Subject: [PATCH] feat(cmd): Replace 'helm get' with 'helm get all' As part of #6552 The is a break in compatibility because 'helm get' is no longer a valid command on its own; what it used to do is now achieved with 'helm get all'. This change avoids confusion between release name and subcommands. It also allows dynamic shell comnpletion to work for 'helm get all'. Signed-off-by: Marc Khouzam --- cmd/helm/get.go | 40 +++--------- cmd/helm/get_all.go | 64 +++++++++++++++++++ cmd/helm/{get_test.go => get_all_test.go} | 14 ++-- cmd/helm/get_notes.go | 4 +- cmd/helm/testdata/output/get-all-no-args.txt | 3 + cmd/helm/testdata/output/get-no-args.txt | 3 - .../testdata/output/get-notes-no-args.txt | 2 +- 7 files changed, 85 insertions(+), 45 deletions(-) create mode 100644 cmd/helm/get_all.go rename cmd/helm/{get_test.go => get_all_test.go} (76%) create mode 100644 cmd/helm/testdata/output/get-all-no-args.txt delete mode 100644 cmd/helm/testdata/output/get-no-args.txt diff --git a/cmd/helm/get.go b/cmd/helm/get.go index b9b38524d..bfb8c2522 100644 --- a/cmd/helm/get.go +++ b/cmd/helm/get.go @@ -23,51 +23,27 @@ import ( "helm.sh/helm/v3/cmd/helm/require" "helm.sh/helm/v3/pkg/action" - "helm.sh/helm/v3/pkg/cli/output" ) var getHelp = ` -This command shows the details of a named release. - -It can be used to get extended information about the release, including: +This command consists of multiple subcommands which can be used to +get extended information about the release, including: - The values used to generate the release - - The chart used to generate the release - The generated manifest file - -By default, this prints a human readable collection of information about the -chart, the supplied values, and the generated manifest file. + - The notes provided by the chart of the release + - The hooks associated with the release ` func newGetCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { - var template string - client := action.NewGet(cfg) - cmd := &cobra.Command{ - Use: "get RELEASE_NAME", - Short: "download a named release", + Use: "get", + Short: "download extended information of a named release", Long: getHelp, - Args: require.ExactArgs(1), - RunE: func(cmd *cobra.Command, args []string) error { - res, err := client.Run(args[0]) - if err != nil { - return err - } - if template != "" { - data := map[string]interface{}{ - "Release": res, - } - return tpl(template, data, out) - } - - return output.Table.Write(out, &statusPrinter{res, true}) - }, + Args: require.NoArgs, } - f := cmd.Flags() - f.IntVar(&client.Version, "revision", 0, "get the named release with revision") - f.StringVar(&template, "template", "", "go template for formatting the output, eg: {{.Release.Name}}") - + cmd.AddCommand(newGetAllCmd(cfg, out)) cmd.AddCommand(newGetValuesCmd(cfg, out)) cmd.AddCommand(newGetManifestCmd(cfg, out)) cmd.AddCommand(newGetHooksCmd(cfg, out)) diff --git a/cmd/helm/get_all.go b/cmd/helm/get_all.go new file mode 100644 index 000000000..8e9ab4d6b --- /dev/null +++ b/cmd/helm/get_all.go @@ -0,0 +1,64 @@ +/* +Copyright The Helm Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package main + +import ( + "io" + + "github.com/spf13/cobra" + + "helm.sh/helm/v3/cmd/helm/require" + "helm.sh/helm/v3/pkg/action" + "helm.sh/helm/v3/pkg/cli/output" +) + +var getAllHelp = ` +This command prints a human readable collection of information about the +notes, hooks, supplied values, and generated manifest file of the given release. +` + +func newGetAllCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { + var template string + client := action.NewGet(cfg) + + cmd := &cobra.Command{ + Use: "all RELEASE_NAME", + Short: "download all information for a named release", + Long: getAllHelp, + Args: require.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + res, err := client.Run(args[0]) + if err != nil { + return err + } + if template != "" { + data := map[string]interface{}{ + "Release": res, + } + return tpl(template, data, out) + } + + return output.Table.Write(out, &statusPrinter{res, true}) + }, + } + + f := cmd.Flags() + f.IntVar(&client.Version, "revision", 0, "get the named release with revision") + f.StringVar(&template, "template", "", "go template for formatting the output, eg: {{.Release.Name}}") + + return cmd +} diff --git a/cmd/helm/get_test.go b/cmd/helm/get_all_test.go similarity index 76% rename from cmd/helm/get_test.go rename to cmd/helm/get_all_test.go index 1279c5f7f..0b026fca4 100644 --- a/cmd/helm/get_test.go +++ b/cmd/helm/get_all_test.go @@ -24,19 +24,19 @@ import ( func TestGetCmd(t *testing.T) { tests := []cmdTestCase{{ - name: "get with a release", - cmd: "get thomas-guide", + name: "get all with a release", + cmd: "get all thomas-guide", golden: "output/get-release.txt", rels: []*release.Release{release.Mock(&release.MockReleaseOptions{Name: "thomas-guide"})}, }, { - name: "get with a formatted release", - cmd: "get elevated-turkey --template {{.Release.Chart.Metadata.Version}}", + name: "get all with a formatted release", + cmd: "get all elevated-turkey --template {{.Release.Chart.Metadata.Version}}", golden: "output/get-release-template.txt", rels: []*release.Release{release.Mock(&release.MockReleaseOptions{Name: "elevated-turkey"})}, }, { - name: "get requires release name arg", - cmd: "get", - golden: "output/get-no-args.txt", + name: "get all requires release name arg", + cmd: "get all", + golden: "output/get-all-no-args.txt", wantError: true, }} runTestCmd(t, tests) diff --git a/cmd/helm/get_notes.go b/cmd/helm/get_notes.go index feab4e303..1b0128989 100644 --- a/cmd/helm/get_notes.go +++ b/cmd/helm/get_notes.go @@ -34,8 +34,8 @@ func newGetNotesCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { client := action.NewGet(cfg) cmd := &cobra.Command{ - Use: "notes [flags] RELEASE_NAME", - Short: "displays the notes of the named release", + Use: "notes RELEASE_NAME", + Short: "download the notes for a named release", Long: getNotesHelp, Args: require.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { diff --git a/cmd/helm/testdata/output/get-all-no-args.txt b/cmd/helm/testdata/output/get-all-no-args.txt new file mode 100644 index 000000000..cc3fc2ad1 --- /dev/null +++ b/cmd/helm/testdata/output/get-all-no-args.txt @@ -0,0 +1,3 @@ +Error: "helm get all" requires 1 argument + +Usage: helm get all RELEASE_NAME [flags] diff --git a/cmd/helm/testdata/output/get-no-args.txt b/cmd/helm/testdata/output/get-no-args.txt deleted file mode 100644 index b911b38c5..000000000 --- a/cmd/helm/testdata/output/get-no-args.txt +++ /dev/null @@ -1,3 +0,0 @@ -Error: "helm get" requires 1 argument - -Usage: helm get RELEASE_NAME [flags] diff --git a/cmd/helm/testdata/output/get-notes-no-args.txt b/cmd/helm/testdata/output/get-notes-no-args.txt index 6523ce8fd..1a0c20caa 100644 --- a/cmd/helm/testdata/output/get-notes-no-args.txt +++ b/cmd/helm/testdata/output/get-notes-no-args.txt @@ -1,3 +1,3 @@ Error: "helm get notes" requires 1 argument -Usage: helm get notes [flags] RELEASE_NAME +Usage: helm get notes RELEASE_NAME [flags]