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 <marc.khouzam@montreal.ca>
pull/6656/head
Marc Khouzam 5 years ago
parent ac732523b1
commit 1d017e3793

@ -23,51 +23,27 @@ import (
"helm.sh/helm/v3/cmd/helm/require" "helm.sh/helm/v3/cmd/helm/require"
"helm.sh/helm/v3/pkg/action" "helm.sh/helm/v3/pkg/action"
"helm.sh/helm/v3/pkg/cli/output"
) )
var getHelp = ` var getHelp = `
This command shows the details of a named release. This command consists of multiple subcommands which can be used to
get extended information about the release, including:
It can be used to get extended information about the release, including:
- The values used to generate the release - The values used to generate the release
- The chart used to generate the release
- The generated manifest file - The generated manifest file
- The notes provided by the chart of the release
By default, this prints a human readable collection of information about the - The hooks associated with the release
chart, the supplied values, and the generated manifest file.
` `
func newGetCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { func newGetCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
var template string
client := action.NewGet(cfg)
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "get RELEASE_NAME", Use: "get",
Short: "download a named release", Short: "download extended information of a named release",
Long: getHelp, Long: getHelp,
Args: require.ExactArgs(1), Args: require.NoArgs,
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() cmd.AddCommand(newGetAllCmd(cfg, out))
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(newGetValuesCmd(cfg, out)) cmd.AddCommand(newGetValuesCmd(cfg, out))
cmd.AddCommand(newGetManifestCmd(cfg, out)) cmd.AddCommand(newGetManifestCmd(cfg, out))
cmd.AddCommand(newGetHooksCmd(cfg, out)) cmd.AddCommand(newGetHooksCmd(cfg, out))

@ -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
}

@ -24,19 +24,19 @@ import (
func TestGetCmd(t *testing.T) { func TestGetCmd(t *testing.T) {
tests := []cmdTestCase{{ tests := []cmdTestCase{{
name: "get with a release", name: "get all with a release",
cmd: "get thomas-guide", cmd: "get all thomas-guide",
golden: "output/get-release.txt", golden: "output/get-release.txt",
rels: []*release.Release{release.Mock(&release.MockReleaseOptions{Name: "thomas-guide"})}, rels: []*release.Release{release.Mock(&release.MockReleaseOptions{Name: "thomas-guide"})},
}, { }, {
name: "get with a formatted release", name: "get all with a formatted release",
cmd: "get elevated-turkey --template {{.Release.Chart.Metadata.Version}}", cmd: "get all elevated-turkey --template {{.Release.Chart.Metadata.Version}}",
golden: "output/get-release-template.txt", golden: "output/get-release-template.txt",
rels: []*release.Release{release.Mock(&release.MockReleaseOptions{Name: "elevated-turkey"})}, rels: []*release.Release{release.Mock(&release.MockReleaseOptions{Name: "elevated-turkey"})},
}, { }, {
name: "get requires release name arg", name: "get all requires release name arg",
cmd: "get", cmd: "get all",
golden: "output/get-no-args.txt", golden: "output/get-all-no-args.txt",
wantError: true, wantError: true,
}} }}
runTestCmd(t, tests) runTestCmd(t, tests)

@ -34,8 +34,8 @@ func newGetNotesCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
client := action.NewGet(cfg) client := action.NewGet(cfg)
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "notes [flags] RELEASE_NAME", Use: "notes RELEASE_NAME",
Short: "displays the notes of the named release", Short: "download the notes for a named release",
Long: getNotesHelp, Long: getNotesHelp,
Args: require.ExactArgs(1), Args: require.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {

@ -0,0 +1,3 @@
Error: "helm get all" requires 1 argument
Usage: helm get all RELEASE_NAME [flags]

@ -1,3 +0,0 @@
Error: "helm get" requires 1 argument
Usage: helm get RELEASE_NAME [flags]

@ -1,3 +1,3 @@
Error: "helm get notes" requires 1 argument Error: "helm get notes" requires 1 argument
Usage: helm get notes [flags] RELEASE_NAME Usage: helm get notes RELEASE_NAME [flags]

Loading…
Cancel
Save