Fix exit after defer.

This commit is contained in:
Mariano Cano 2021-10-07 12:43:24 -07:00
parent 48549bf317
commit 205148ad1f
5 changed files with 24 additions and 6 deletions

View file

@ -33,7 +33,6 @@ func main() {
// Initialize windows terminal
ui.Init()
defer ui.Reset()
c, err := awskms.New(context.Background(), apiv1.Options{
Type: string(apiv1.AmazonKMS),
@ -54,10 +53,14 @@ func main() {
fatal(err)
}
}
// Reset windows terminal
ui.Reset()
}
func fatal(err error) {
fmt.Fprintln(os.Stderr, err)
ui.Reset()
os.Exit(1)
}

View file

@ -53,6 +53,11 @@ func init() {
rand.Seed(time.Now().UnixNano())
}
func exit(code int) {
ui.Reset()
os.Exit(code)
}
// appHelpTemplate contains the modified template for the main app
var appHelpTemplate = `## NAME
**{{.HelpName}}** -- {{.Usage}}
@ -93,7 +98,6 @@ Please send us a sentence or two, good or bad: **feedback@smallstep.com** or htt
func main() {
// Initialize windows terminal
ui.Init()
defer ui.Reset()
// Override global framework components
cli.VersionPrinter = func(c *cli.Context) {
@ -169,8 +173,10 @@ $ step-ca $STEPPATH/config/ca.json --password-file ./password.txt
} else {
fmt.Fprintln(os.Stderr, err)
}
os.Exit(1)
exit(1)
}
exit(0)
}
func flagValue(f cli.Flag) reflect.Value {

View file

@ -64,7 +64,6 @@ func main() {
// Initialize windows terminal
ui.Init()
defer ui.Reset()
c, err := cloudkms.New(context.Background(), apiv1.Options{
Type: string(apiv1.CloudKMS),
@ -84,10 +83,14 @@ func main() {
fatal(err)
}
}
// Reset windows terminal
ui.Reset()
}
func fatal(err error) {
fmt.Fprintln(os.Stderr, err)
ui.Reset()
os.Exit(1)
}

View file

@ -131,7 +131,6 @@ func main() {
// Initialize windows terminal
ui.Init()
defer ui.Reset()
if u.Get("pin-value") == "" && u.Get("pin-source") == "" && c.Pin == "" {
pin, err := ui.PromptPassword("What is the PKCS#11 PIN?")
@ -205,6 +204,9 @@ func main() {
if err := createPKI(k, c); err != nil {
fatalClose(err, k)
}
// Reset windows terminal
ui.Reset()
}
func fatal(err error) {
@ -213,6 +215,7 @@ func fatal(err error) {
} else {
fmt.Fprintln(os.Stderr, err)
}
ui.Reset()
os.Exit(1)
}

View file

@ -89,7 +89,6 @@ func main() {
// Initialize windows terminal
ui.Init()
defer ui.Reset()
pin, err := ui.PromptPassword("What is the YubiKey PIN?")
if err != nil {
@ -123,6 +122,9 @@ func main() {
defer func() {
_ = k.Close()
}()
// Reset windows terminal
ui.Reset()
}
func fatal(err error) {
@ -131,6 +133,7 @@ func fatal(err error) {
} else {
fmt.Fprintln(os.Stderr, err)
}
ui.Reset()
os.Exit(1)
}