diff --git a/pkg/action/show.go b/pkg/action/show.go index bd2e08f6a..1e3da3bdc 100644 --- a/pkg/action/show.go +++ b/pkg/action/show.go @@ -109,14 +109,13 @@ func (s *Show) Run(chartpath string) (string, error) { } if s.OutputFormat == ShowReadme || s.OutputFormat == ShowAll { - if s.OutputFormat == ShowAll { - fmt.Fprintln(&out, "---") - } readme := findReadme(s.chart.Files) - if readme == nil { - return out.String(), nil + if readme != nil { + if s.OutputFormat == ShowAll { + fmt.Fprintln(&out, "---") + } + fmt.Fprintf(&out, "%s\n", readme.Data) } - fmt.Fprintf(&out, "%s\n", readme.Data) } if s.OutputFormat == ShowCRDs || s.OutputFormat == ShowAll { diff --git a/pkg/action/show_test.go b/pkg/action/show_test.go index fda74caba..983bcfe05 100644 --- a/pkg/action/show_test.go +++ b/pkg/action/show_test.go @@ -120,3 +120,33 @@ bar t.Errorf("Expected\n%q\nGot\n%q\n", expect, output) } } + +func TestShowNoReadme(t *testing.T) { + client := NewShow(ShowAll) + client.chart = &chart.Chart{ + Metadata: &chart.Metadata{Name: "alpine"}, + Files: []*chart.File{ + {Name: "crds/ignoreme.txt", Data: []byte("error")}, + {Name: "crds/foo.yaml", Data: []byte("---\nfoo\n")}, + {Name: "crds/bar.json", Data: []byte("---\nbar\n")}, + }, + } + + output, err := client.Run("") + if err != nil { + t.Fatal(err) + } + + expect := `name: alpine + +--- +foo + +--- +bar + +` + if output != expect { + t.Errorf("Expected\n%q\nGot\n%q\n", expect, output) + } +}