summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDave Henderson <dhenderson@gmail.com>2018-07-16 23:36:23 -0400
committerDave Henderson <dhenderson@gmail.com>2018-07-17 00:06:49 -0400
commit65188db38ebde5457581aa43e537cfa8a824a13a (patch)
tree71a8c2572b2d3ba86579b4c9e14090e6940b9f7a
parent88dd5b24de06d8a81fb2477680ab3252fcd1f69a (diff)
Reducing output on template errors
Signed-off-by: Dave Henderson <dhenderson@gmail.com>
-rw-r--r--cmd/gomplate/main.go8
-rw-r--r--tests/integration/basic_test.go14
-rw-r--r--tests/integration/inputdir_test.go2
-rw-r--r--tests/integration/strings_test.go4
4 files changed, 16 insertions, 12 deletions
diff --git a/cmd/gomplate/main.go b/cmd/gomplate/main.go
index 1ddcf120..bde6eb46 100644
--- a/cmd/gomplate/main.go
+++ b/cmd/gomplate/main.go
@@ -80,7 +80,11 @@ func newGomplateCmd() *cobra.Command {
printVersion(cmd.Name())
return nil
}
- return gomplate.RunTemplates(&opts)
+
+ err := gomplate.RunTemplates(&opts)
+ cmd.SilenceErrors = true
+ cmd.SilenceUsage = true
+ return err
},
PostRunE: postRunExec,
Args: optionalExecArgs,
@@ -111,7 +115,7 @@ func main() {
command := newGomplateCmd()
initFlags(command)
if err := command.Execute(); err != nil {
- fmt.Println(err)
+ fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
diff --git a/tests/integration/basic_test.go b/tests/integration/basic_test.go
index 2565341b..de890905 100644
--- a/tests/integration/basic_test.go
+++ b/tests/integration/basic_test.go
@@ -73,7 +73,7 @@ func (s *BasicSuite) TestErrorsWithInputOutputImbalance(c *C) {
})
result.Assert(c, icmd.Expected{
ExitCode: 1,
- Err: "Error: Must provide same number of --out (1) as --file (2) options",
+ Err: "Must provide same number of --out (1) as --file (2) options",
})
}
@@ -101,31 +101,31 @@ func (s *BasicSuite) TestFlagRules(c *C) {
result := icmd.RunCommand(GomplateBin, "-f", "-", "-i", "HELLO WORLD")
result.Assert(c, icmd.Expected{
ExitCode: 1,
- Out: "--in and --file may not be used together",
+ Err: "--in and --file may not be used together",
})
result = icmd.RunCommand(GomplateBin, "--output-dir", ".")
result.Assert(c, icmd.Expected{
ExitCode: 1,
- Out: "--input-dir must be set when --output-dir is set",
+ Err: "--input-dir must be set when --output-dir is set",
})
result = icmd.RunCommand(GomplateBin, "--input-dir", ".", "--in", "param")
result.Assert(c, icmd.Expected{
ExitCode: 1,
- Out: "--input-dir can not be used together with --in or --file",
+ Err: "--input-dir can not be used together with --in or --file",
})
result = icmd.RunCommand(GomplateBin, "--input-dir", ".", "--file", "input.txt")
result.Assert(c, icmd.Expected{
ExitCode: 1,
- Out: "--input-dir can not be used together with --in or --file",
+ Err: "--input-dir can not be used together with --in or --file",
})
result = icmd.RunCommand(GomplateBin, "--output-dir", ".", "--out", "param")
result.Assert(c, icmd.Expected{
ExitCode: 1,
- Out: "--output-dir can not be used together with --out",
+ Err: "--output-dir can not be used together with --out",
})
}
@@ -150,7 +150,7 @@ func (s *BasicSuite) TestDelimsChangedThroughEnvVars(c *C) {
func (s *BasicSuite) TestUnknownArgErrors(c *C) {
result := icmd.RunCommand(GomplateBin, "-in", "flibbit")
- result.Assert(c, icmd.Expected{ExitCode: 1, Out: `unknown command "flibbit" for "gomplate"`})
+ result.Assert(c, icmd.Expected{ExitCode: 1, Err: `unknown command "flibbit" for "gomplate"`})
}
func (s *BasicSuite) TestExecCommand(c *C) {
diff --git a/tests/integration/inputdir_test.go b/tests/integration/inputdir_test.go
index 6c0bbf88..2230e5a1 100644
--- a/tests/integration/inputdir_test.go
+++ b/tests/integration/inputdir_test.go
@@ -99,6 +99,6 @@ func (s *InputDirSuite) TestReportsFilenameWithBadInputFile(c *C) {
)
result.Assert(c, icmd.Expected{
ExitCode: 1,
- Out: "template: " + s.tmpDir.Join("bad_in", "bad.tmpl") + ":1: unexpected {{end}}",
+ Err: "template: " + s.tmpDir.Join("bad_in", "bad.tmpl") + ":1: unexpected {{end}}",
})
}
diff --git a/tests/integration/strings_test.go b/tests/integration/strings_test.go
index c8843de5..affd8f32 100644
--- a/tests/integration/strings_test.go
+++ b/tests/integration/strings_test.go
@@ -37,11 +37,11 @@ func (s *StringsSuite) TestRepeat(c *C) {
result = icmd.RunCommand(GomplateBin, "-i",
`ba{{ strings.Repeat 9223372036854775807 "na" }}`)
- result.Assert(c, icmd.Expected{ExitCode: 1, Out: `too long: causes overflow`})
+ result.Assert(c, icmd.Expected{ExitCode: 1, Err: `too long: causes overflow`})
result = icmd.RunCommand(GomplateBin, "-i",
`ba{{ strings.Repeat -1 "na" }}`)
- result.Assert(c, icmd.Expected{ExitCode: 1, Out: `negative count`})
+ result.Assert(c, icmd.Expected{ExitCode: 1, Err: `negative count`})
}
func (s *StringsSuite) TestSlug(c *C) {