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 <ansverma@localhost.localdomain>
pull/7753/head
Anshul Verma 5 years ago
parent ec1d1a3d3e
commit 51dd8313bc

@ -83,6 +83,27 @@ func newListCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
} }
if client.Short { 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 { for _, res := range results {
fmt.Fprintln(out, res.Name) fmt.Fprintln(out, res.Name)
} }

@ -198,6 +198,16 @@ func TestListCmd(t *testing.T) {
cmd: "list --short", cmd: "list --short",
golden: "output/list-short.txt", golden: "output/list-short.txt",
rels: releaseFixture, 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", name: "list superseded releases",
cmd: "list --superseded", cmd: "list --superseded",

Loading…
Cancel
Save