summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cmd/gomplate/main.go13
1 files changed, 6 insertions, 7 deletions
diff --git a/cmd/gomplate/main.go b/cmd/gomplate/main.go
index 7cc37162..17caa9e2 100644
--- a/cmd/gomplate/main.go
+++ b/cmd/gomplate/main.go
@@ -11,16 +11,15 @@ import (
)
func main() {
- exitCode := 0
- // defer the exit first, so it executes last, to let the deferred cancel run
- defer func() { os.Exit(exitCode) }()
+ if err := run(); err != nil {
+ os.Exit(1)
+ }
+}
+func run() error {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
// need to strip os.Args[0] so we only pass the actual flags
- err := cmd.Main(ctx, os.Args[1:], os.Stdin, os.Stdout, os.Stderr)
- if err != nil {
- exitCode = 1
- }
+ return cmd.Main(ctx, os.Args[1:], os.Stdin, os.Stdout, os.Stderr)
}