diff --git a/pkg/cmd/gist/view/view.go b/pkg/cmd/gist/view/view.go index 9d8b41110..31b48325f 100644 --- a/pkg/cmd/gist/view/view.go +++ b/pkg/cmd/gist/view/view.go @@ -89,11 +89,6 @@ func viewRun(opts *ViewOptions) error { return err } - cs := opts.IO.ColorScheme() - if gist.Description != "" { - fmt.Fprintf(opts.IO.Out, "%s\n", cs.Bold(gist.Description)) - } - if opts.Filename != "" { gistFile, ok := gist.Files[opts.Filename] if !ok { @@ -107,6 +102,11 @@ func viewRun(opts *ViewOptions) error { showFilenames := len(gist.Files) > 1 + cs := opts.IO.ColorScheme() + if gist.Description != "" && showFilenames { + fmt.Fprintf(opts.IO.Out, "%s\n", cs.Bold(gist.Description)) + } + outs := []string{} // to ensure consistent ordering for filename, gistFile := range gist.Files { diff --git a/pkg/cmd/gist/view/view_test.go b/pkg/cmd/gist/view/view_test.go index 0ddf55f49..832a9ae01 100644 --- a/pkg/cmd/gist/view/view_test.go +++ b/pkg/cmd/gist/view/view_test.go @@ -131,6 +131,27 @@ func Test_viewRun(t *testing.T) { }, wantOut: "bwhiizzzbwhuiiizzzz\n\n", }, + { + name: "filename selected, raw", + opts: &ViewOptions{ + Selector: "1234", + Filename: "cicada.txt", + Raw: true, + }, + gist: &shared.Gist{ + Files: map[string]*shared.GistFile{ + "cicada.txt": { + Content: "bwhiizzzbwhuiiizzzz", + Type: "text/plain", + }, + "foo.md": { + Content: "# foo", + Type: "application/markdown", + }, + }, + }, + wantOut: "bwhiizzzbwhuiiizzzz\n\n", + }, { name: "multiple files, no description", opts: &ViewOptions{ @@ -171,7 +192,7 @@ func Test_viewRun(t *testing.T) { wantOut: "some files\ncicada.txt\n\nbwhiizzzbwhuiiizzzz\n\nfoo.md\n\n\n \n • foo \n\n\n\n", }, { - name: "raw", + name: "multiple files, raw", opts: &ViewOptions{ Selector: "1234", Raw: true,