From 232dc7b7fa6559de74bd6b4b5902fd7985a772fe Mon Sep 17 00:00:00 2001 From: Ruslan Gilyazetdinov Date: Tue, 2 Feb 2021 10:54:07 +0300 Subject: [PATCH] change condition for single file, remove empty lines in single file mode --- pkg/cmd/gist/view/view.go | 15 +++++++++------ pkg/cmd/gist/view/view_test.go | 4 ++-- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/pkg/cmd/gist/view/view.go b/pkg/cmd/gist/view/view.go index 31b48325f..4f95af803 100644 --- a/pkg/cmd/gist/view/view.go +++ b/pkg/cmd/gist/view/view.go @@ -89,6 +89,11 @@ func viewRun(opts *ViewOptions) error { return err } + cs := opts.IO.ColorScheme() + if gist.Description != "" && opts.Filename == "" { + fmt.Fprintf(opts.IO.Out, "%s\n", cs.Bold(gist.Description)) + } + if opts.Filename != "" { gistFile, ok := gist.Files[opts.Filename] if !ok { @@ -102,11 +107,6 @@ 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 { @@ -122,7 +122,10 @@ func viewRun(opts *ViewOptions) error { content = rendered } } - out += fmt.Sprintf("%s\n\n", content) + out += fmt.Sprintf("%s", content) + if opts.Filename == "" { + out += fmt.Sprintf("\n\n") + } outs = append(outs, out) } diff --git a/pkg/cmd/gist/view/view_test.go b/pkg/cmd/gist/view/view_test.go index 832a9ae01..4ecd86538 100644 --- a/pkg/cmd/gist/view/view_test.go +++ b/pkg/cmd/gist/view/view_test.go @@ -129,7 +129,7 @@ func Test_viewRun(t *testing.T) { }, }, }, - wantOut: "bwhiizzzbwhuiiizzzz\n\n", + wantOut: "bwhiizzzbwhuiiizzzz", }, { name: "filename selected, raw", @@ -150,7 +150,7 @@ func Test_viewRun(t *testing.T) { }, }, }, - wantOut: "bwhiizzzbwhuiiizzzz\n\n", + wantOut: "bwhiizzzbwhuiiizzzz", }, { name: "multiple files, no description",