From f25e0d607362857144bd9bfd263213262e5f1f93 Mon Sep 17 00:00:00 2001 From: Daniel Pap Date: Sun, 10 Dec 2023 05:55:25 +0100 Subject: [PATCH] show crds command output separated by document separator Signed-off-by: Daniel Pap --- pkg/action/show.go | 6 +++--- pkg/action/show_test.go | 8 ++++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/pkg/action/show.go b/pkg/action/show.go index 6ed855b83..46ba81ff6 100644 --- a/pkg/action/show.go +++ b/pkg/action/show.go @@ -139,10 +139,10 @@ func (s *Show) Run(chartpath string) (string, error) { if s.OutputFormat == ShowCRDs || s.OutputFormat == ShowAll { crds := s.chart.CRDObjects() if len(crds) > 0 { - if s.OutputFormat == ShowAll && !bytes.HasPrefix(crds[0].File.Data, []byte("---")) { - fmt.Fprintln(&out, "---") - } for _, crd := range crds { + if !bytes.HasPrefix(crd.File.Data, []byte("---")) { + fmt.Fprintln(&out, "---") + } fmt.Fprintf(&out, "%s\n", string(crd.File.Data)) } } diff --git a/pkg/action/show_test.go b/pkg/action/show_test.go index 8b617ea85..ab6f464ec 100644 --- a/pkg/action/show_test.go +++ b/pkg/action/show_test.go @@ -32,6 +32,7 @@ func TestShow(t *testing.T) { {Name: "crds/ignoreme.txt", Data: []byte("error")}, {Name: "crds/foo.yaml", Data: []byte("---\nfoo\n")}, {Name: "crds/bar.json", Data: []byte("---\nbar\n")}, + {Name: "crds/baz.yaml", Data: []byte("baz\n")}, }, Raw: []*chart.File{ {Name: "values.yaml", Data: []byte("VALUES\n")}, @@ -58,6 +59,9 @@ foo --- bar +--- +baz + ` if output != expect { t.Errorf("Expected\n%q\nGot\n%q\n", expect, output) @@ -102,6 +106,7 @@ func TestShowCRDs(t *testing.T) { {Name: "crds/ignoreme.txt", Data: []byte("error")}, {Name: "crds/foo.yaml", Data: []byte("---\nfoo\n")}, {Name: "crds/bar.json", Data: []byte("---\nbar\n")}, + {Name: "crds/baz.yaml", Data: []byte("baz\n")}, }, } @@ -116,6 +121,9 @@ foo --- bar +--- +baz + ` if output != expect { t.Errorf("Expected\n%q\nGot\n%q\n", expect, output)