From 92616afcbf594a3db08006279a5cc25e2209d011 Mon Sep 17 00:00:00 2001 From: Dave Henderson Date: Sun, 17 Jan 2021 19:16:30 -0500 Subject: Only print newline to when outputting to os.Stdout Signed-off-by: Dave Henderson --- internal/cmd/main.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/internal/cmd/main.go b/internal/cmd/main.go index 9217a725..5cbbc47a 100644 --- a/internal/cmd/main.go +++ b/internal/cmd/main.go @@ -95,11 +95,13 @@ func NewGomplateCmd() *cobra.Command { // print a newline to stderr for convenience if the output is going // to stdout, since otherwise the shell prompt may look wrong - // Note: once stdin/out/err are externalized we should only do this - // if stdout isn't ending with its own newline! - if len(cfg.OutputFiles) == 0 || (len(cfg.OutputFiles) == 1 && cfg.OutputFiles[0] == "-") && !cfg.ExecPipe { + // TODO: consider only doing this if stdout doesn't have a trailing + // newline already. + if len(cfg.OutputFiles) == 0 || (len(cfg.OutputFiles) == 1 && cfg.OutputFiles[0] == "-") && + !cfg.ExecPipe && cfg.Stdout == os.Stdout { fmt.Fprintf(cmd.ErrOrStderr(), "\n") } + log.Debug().Int("templatesRendered", gomplate.Metrics.TemplatesProcessed). Int("errors", gomplate.Metrics.Errors). Dur("duration", gomplate.Metrics.TotalRenderDuration). -- cgit v1.2.3