change condition for single file, remove empty lines in single file mode

This commit is contained in:
Ruslan Gilyazetdinov 2021-02-02 10:54:07 +03:00
parent 8e86129e2e
commit 232dc7b7fa
2 changed files with 11 additions and 8 deletions

View file

@ -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)
}

View file

@ -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",