Merge pull request #12624 from papdaniel/main

show crds command output separated by document separator
pull/31132/head
Joe Julian 1 month ago committed by GitHub
commit e1b9173812
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -129,10 +129,10 @@ func (s *Show) Run(chartpath string) (string, error) {
if s.OutputFormat == ShowCRDs || s.OutputFormat == ShowAll { if s.OutputFormat == ShowCRDs || s.OutputFormat == ShowAll {
crds := s.chart.CRDObjects() crds := s.chart.CRDObjects()
if len(crds) > 0 { if len(crds) > 0 {
if s.OutputFormat == ShowAll && !bytes.HasPrefix(crds[0].File.Data, []byte("---")) {
fmt.Fprintln(&out, "---")
}
for _, crd := range crds { for _, crd := range crds {
if !bytes.HasPrefix(crd.File.Data, []byte("---")) {
fmt.Fprintln(&out, "---")
}
fmt.Fprintf(&out, "%s\n", string(crd.File.Data)) fmt.Fprintf(&out, "%s\n", string(crd.File.Data))
} }
} }

@ -32,6 +32,7 @@ func TestShow(t *testing.T) {
{Name: "crds/ignoreme.txt", Data: []byte("error")}, {Name: "crds/ignoreme.txt", Data: []byte("error")},
{Name: "crds/foo.yaml", Data: []byte("---\nfoo\n")}, {Name: "crds/foo.yaml", Data: []byte("---\nfoo\n")},
{Name: "crds/bar.json", Data: []byte("---\nbar\n")}, {Name: "crds/bar.json", Data: []byte("---\nbar\n")},
{Name: "crds/baz.yaml", Data: []byte("baz\n")},
}, },
Raw: []*chart.File{ Raw: []*chart.File{
{Name: "values.yaml", Data: []byte("VALUES\n")}, {Name: "values.yaml", Data: []byte("VALUES\n")},
@ -58,6 +59,9 @@ foo
--- ---
bar bar
---
baz
` `
if output != expect { if output != expect {
t.Errorf("Expected\n%q\nGot\n%q\n", expect, output) t.Errorf("Expected\n%q\nGot\n%q\n", expect, output)
@ -105,6 +109,7 @@ func TestShowCRDs(t *testing.T) {
{Name: "crds/ignoreme.txt", Data: []byte("error")}, {Name: "crds/ignoreme.txt", Data: []byte("error")},
{Name: "crds/foo.yaml", Data: []byte("---\nfoo\n")}, {Name: "crds/foo.yaml", Data: []byte("---\nfoo\n")},
{Name: "crds/bar.json", Data: []byte("---\nbar\n")}, {Name: "crds/bar.json", Data: []byte("---\nbar\n")},
{Name: "crds/baz.yaml", Data: []byte("baz\n")},
}, },
} }
@ -119,6 +124,9 @@ foo
--- ---
bar bar
---
baz
` `
if output != expect { if output != expect {
t.Errorf("Expected\n%q\nGot\n%q\n", expect, output) t.Errorf("Expected\n%q\nGot\n%q\n", expect, output)

Loading…
Cancel
Save