From 51dd8313bcbc03db3f266dc6217d6fce70fe39d3 Mon Sep 17 00:00:00 2001 From: Anshul Verma Date: Tue, 10 Mar 2020 03:35:59 +0530 Subject: [PATCH 1/4] Solve the issue #7749 where proper formating was not being done if --short(-q) option was used with other formating options like json, yaml Signed-off-by: Anshul Verma --- cmd/helm/list.go | 21 ++++++++++++++++++++ cmd/helm/list_test.go | 10 ++++++++++ cmd/helm/testdata/output/list-short-json.txt | 0 cmd/helm/testdata/output/list-short-yaml.txt | 0 4 files changed, 31 insertions(+) create mode 100644 cmd/helm/testdata/output/list-short-json.txt create mode 100644 cmd/helm/testdata/output/list-short-yaml.txt diff --git a/cmd/helm/list.go b/cmd/helm/list.go index 4b652088d..59364381e 100644 --- a/cmd/helm/list.go +++ b/cmd/helm/list.go @@ -83,6 +83,27 @@ func newListCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { } if client.Short { + + names := make([]string, 0) + for _, res := range results { + //fmt.Fprintln(out, res.Name) + names = append(names, res.Name) + } + + outputFlag := cmd.Flag("output") + if outputFlag.Changed { + switch outputFlag.Value.String() { + case "json": + output.EncodeJSON(out, names) + return nil + case "yaml": + output.EncodeYAML(out, names) + return nil + default: + return outfmt.Write(out, newReleaseListWriter(results)) + } + } + for _, res := range results { fmt.Fprintln(out, res.Name) } diff --git a/cmd/helm/list_test.go b/cmd/helm/list_test.go index fe773a803..dadb57b94 100644 --- a/cmd/helm/list_test.go +++ b/cmd/helm/list_test.go @@ -198,6 +198,16 @@ func TestListCmd(t *testing.T) { cmd: "list --short", golden: "output/list-short.txt", rels: releaseFixture, + }, { + name: "list releases in short output format", + cmd: "list --short --output yaml", + golden: "output/list-short-yaml.txt", + rels: releaseFixture, + }, { + name: "list releases in short output format", + cmd: "list --short --output json", + golden: "output/list-short-json.txt", + rels: releaseFixture, }, { name: "list superseded releases", cmd: "list --superseded", diff --git a/cmd/helm/testdata/output/list-short-json.txt b/cmd/helm/testdata/output/list-short-json.txt new file mode 100644 index 000000000..e69de29bb diff --git a/cmd/helm/testdata/output/list-short-yaml.txt b/cmd/helm/testdata/output/list-short-yaml.txt new file mode 100644 index 000000000..e69de29bb From 7470337d32cef71043a3da1a23a6b3004e618ed6 Mon Sep 17 00:00:00 2001 From: Anshul Verma Date: Tue, 10 Mar 2020 03:42:43 +0530 Subject: [PATCH 2/4] Solve the issue #7749 where proper formating was not being done if --short(-q) option was used with other formating options like json, yaml Signed-off-by: Anshul Verma --- cmd/helm/testdata/output/list-short-json.txt | 1 + cmd/helm/testdata/output/list-short-yaml.txt | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/cmd/helm/testdata/output/list-short-json.txt b/cmd/helm/testdata/output/list-short-json.txt index e69de29bb..1ab52136b 100644 --- a/cmd/helm/testdata/output/list-short-json.txt +++ b/cmd/helm/testdata/output/list-short-json.txt @@ -0,0 +1 @@ +["hummingbird","iguana","rocket","starlord"] \ No newline at end of file diff --git a/cmd/helm/testdata/output/list-short-yaml.txt b/cmd/helm/testdata/output/list-short-yaml.txt index e69de29bb..41459282f 100644 --- a/cmd/helm/testdata/output/list-short-yaml.txt +++ b/cmd/helm/testdata/output/list-short-yaml.txt @@ -0,0 +1,4 @@ +- hummingbird +- iguana +- rocket +- starlord \ No newline at end of file From c354de80e5ab2a4ff07007353451dcb1b50b5801 Mon Sep 17 00:00:00 2001 From: Anshul Verma Date: Tue, 10 Mar 2020 03:47:21 +0530 Subject: [PATCH 3/4] Solve the issue #7749 where proper formating was not being done if --short(-q) option was used with other formating options like json, yaml Signed-off-by: Anshul Verma --- cmd/helm/testdata/output/list-short-json.txt | 2 +- cmd/helm/testdata/output/list-short-yaml.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/helm/testdata/output/list-short-json.txt b/cmd/helm/testdata/output/list-short-json.txt index 1ab52136b..acbf1e44d 100644 --- a/cmd/helm/testdata/output/list-short-json.txt +++ b/cmd/helm/testdata/output/list-short-json.txt @@ -1 +1 @@ -["hummingbird","iguana","rocket","starlord"] \ No newline at end of file +["hummingbird","iguana","rocket","starlord"] diff --git a/cmd/helm/testdata/output/list-short-yaml.txt b/cmd/helm/testdata/output/list-short-yaml.txt index 41459282f..86fb3d670 100644 --- a/cmd/helm/testdata/output/list-short-yaml.txt +++ b/cmd/helm/testdata/output/list-short-yaml.txt @@ -1,4 +1,4 @@ - hummingbird - iguana - rocket -- starlord \ No newline at end of file +- starlord From 4113fc8951a891a934028081417fc70e1a1b1f63 Mon Sep 17 00:00:00 2001 From: Anshul Verma Date: Wed, 11 Mar 2020 01:04:50 +0530 Subject: [PATCH 4/4] Solve the issue #7749 where proper formating was not being done if --short(-q) option was used with other formating options like json, yaml Signed-off-by: Anshul Verma --- cmd/helm/list.go | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/cmd/helm/list.go b/cmd/helm/list.go index 59364381e..08d6beb79 100644 --- a/cmd/helm/list.go +++ b/cmd/helm/list.go @@ -86,28 +86,26 @@ func newListCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { names := make([]string, 0) for _, res := range results { - //fmt.Fprintln(out, res.Name) names = append(names, res.Name) } outputFlag := cmd.Flag("output") - if outputFlag.Changed { - switch outputFlag.Value.String() { - case "json": - output.EncodeJSON(out, names) - return nil - case "yaml": - output.EncodeYAML(out, names) - return nil - default: - return outfmt.Write(out, newReleaseListWriter(results)) - } - } - for _, res := range results { - fmt.Fprintln(out, res.Name) + switch outputFlag.Value.String() { + case "json": + output.EncodeJSON(out, names) + return nil + case "yaml": + output.EncodeYAML(out, names) + return nil + case "table": + for _, res := range results { + fmt.Fprintln(out, res.Name) + } + return nil + default: + return outfmt.Write(out, newReleaseListWriter(results)) } - return nil } return outfmt.Write(out, newReleaseListWriter(results))