From ee3b76b980f5357e47921d2f54d17fe0e0ec58f8 Mon Sep 17 00:00:00 2001 From: Marc Abramowitz Date: Wed, 18 May 2016 23:02:02 -0700 Subject: [PATCH] Terminate all JSON output with a newline I think it would be nice if the output always ended with a newline. It's weird when it doesn't because the next prompt starts on the same line as the last line of output and that just doesn't look great. Also it's nice to have the output end with a newline because then you can redirect to a file and have that file adhere to POSIX standards - e.g.: - http://stackoverflow.com/questions/729692/why-should-text-files-end-with-a-newline Fixes: GH-23 --- commands/output.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/commands/output.go b/commands/output.go index fc3f474..9397f09 100644 --- a/commands/output.go +++ b/commands/output.go @@ -32,6 +32,13 @@ func (c *Cmd) OutputJSON(v interface{}, prettyFlag bool) error { fmt.Fprintf(c.Out, string(jsonRaw)) + jsonStr := string(jsonRaw) + if strings.HasSuffix(jsonStr, "\n") { + fmt.Fprintf(c.Out, jsonStr) + } else { + fmt.Fprintf(c.Out, jsonStr+"\n") + } + return nil }