summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDave Henderson <dhenderson@gmail.com>2021-03-20 09:17:20 -0400
committerDave Henderson <dhenderson@gmail.com>2021-03-20 09:17:20 -0400
commitc17a496567eb1824937726a50f73ddeeb0b5a520 (patch)
treeb08bb7ff3438db795f01eab6a22799e54c143271
parentefca627b22d28dc58b295482c9e052ebba2f0c2b (diff)
Stop printing newline on stderr when outputting to stdout
Signed-off-by: Dave Henderson <dhenderson@gmail.com>
-rw-r--r--internal/cmd/main.go15
-rw-r--r--internal/tests/integration/basic_test.go9
2 files changed, 4 insertions, 20 deletions
diff --git a/internal/cmd/main.go b/internal/cmd/main.go
index 3246d808..88184699 100644
--- a/internal/cmd/main.go
+++ b/internal/cmd/main.go
@@ -2,7 +2,6 @@ package cmd
import (
"context"
- "fmt"
"io"
"os"
"os/exec"
@@ -106,12 +105,6 @@ func NewGomplateCmd() *cobra.Command {
cmd.SilenceErrors = true
cmd.SilenceUsage = true
- // print a newline to stderr for convenience if the output is going
- // to stdout, since otherwise the shell prompt may look wrong
- if consoleOutput(cfg) {
- fmt.Fprintf(cmd.ErrOrStderr(), "\n")
- }
-
log.Debug().Int("templatesRendered", gomplate.Metrics.TemplatesProcessed).
Int("errors", gomplate.Metrics.Errors).
Dur("duration", gomplate.Metrics.TotalRenderDuration).
@@ -127,14 +120,6 @@ func NewGomplateCmd() *cobra.Command {
return rootCmd
}
-// TODO: consider only doing this if stdout doesn't have a trailing newline
-// already.
-func consoleOutput(cfg *config.Config) bool {
- consoleOnly := len(cfg.OutputFiles) == 0 || (len(cfg.OutputFiles) == 1 && cfg.OutputFiles[0] == "-")
- usingDirs := cfg.InputDir != "" && cfg.OutputDir != ""
- return consoleOnly && !usingDirs && !cfg.ExecPipe && cfg.Stdout == os.Stdout
-}
-
// InitFlags - initialize the various flags and help strings on the command.
// Note that the defaults set here are ignored, and instead defaults from
// *config.Config's ApplyDefaults method are used instead. Changes here must be
diff --git a/internal/tests/integration/basic_test.go b/internal/tests/integration/basic_test.go
index 408ddce5..4f39058f 100644
--- a/internal/tests/integration/basic_test.go
+++ b/internal/tests/integration/basic_test.go
@@ -45,7 +45,7 @@ func (s *BasicSuite) TestTakesStdinByDefault(c *C) {
cmd.Stdin = bytes.NewBufferString("hello world")
})
result.Assert(c, icmd.Expected{ExitCode: 0, Out: "hello world"})
- assert.Equal(c, "hello world\n", result.Combined())
+ assert.Equal(c, "hello world", result.Combined())
}
func (s *BasicSuite) TestTakesStdinWithFileFlag(c *C) {
@@ -53,15 +53,14 @@ func (s *BasicSuite) TestTakesStdinWithFileFlag(c *C) {
cmd.Stdin = bytes.NewBufferString("hello world")
})
result.Assert(c, icmd.Expected{ExitCode: 0, Out: "hello world"})
- assert.Equal(c, "hello world\n", result.Combined())
+ assert.Equal(c, "hello world", result.Combined())
}
func (s *BasicSuite) TestWritesToStdoutWithOutFlag(c *C) {
result := icmd.RunCmd(icmd.Command(GomplateBin, "--out", "-"), func(cmd *icmd.Cmd) {
cmd.Stdin = bytes.NewBufferString("hello world")
})
assert.Equal(c, 0, result.ExitCode)
- assert.Equal(c, "hello world", result.Stdout())
- assert.Equal(c, "\n", result.Stderr())
+ assert.Equal(c, "hello world", result.Combined())
}
func (s *BasicSuite) TestIgnoresStdinWithInFlag(c *C) {
@@ -69,7 +68,7 @@ func (s *BasicSuite) TestIgnoresStdinWithInFlag(c *C) {
cmd.Stdin = bytes.NewBufferString("hello world")
})
result.Assert(c, icmd.Expected{ExitCode: 0, Out: "hi"})
- assert.Equal(c, "hi\n", result.Combined())
+ assert.Equal(c, "hi", result.Combined())
}
func (s *BasicSuite) TestErrorsWithInputOutputImbalance(c *C) {