Created
October 4, 2021 01:19
-
-
Save carolynvs/e8c4c787a802d8be01646ab6b0d1c428 to your computer and use it in GitHub Desktop.
exit main and execute defered statements
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func main() { | |
run := func() int { | |
p := porter.New() | |
defer p.Close() | |
cmd := buildRootCommandFrom(p) | |
if err := cmd.Execute(); err != nil { | |
return 1 | |
} | |
return 0 | |
} | |
// Wrapping the main run logic in a function because os.Exit will not | |
// execute defer statements | |
os.Exit(run()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment