diff --git a/cmd/gomplate/main.go b/cmd/gomplate/main.go index 7cc371623..17caa9e25 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) }