Fix exit after defer.

pull/719/head
Mariano Cano 3 years ago
parent 48549bf317
commit 205148ad1f

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

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

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

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

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

Loading…
Cancel
Save