Mariano Cano 5 лет назад
Родитель
Сommit
205148ad1f

+ 4 - 1
cmd/step-awskms-init/main.go

@@ -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)
 }
 

+ 8 - 2
cmd/step-ca/main.go

@@ -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 {

+ 4 - 1
cmd/step-cloudkms-init/main.go

@@ -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)
 }
 

+ 4 - 1
cmd/step-pkcs11-init/main.go

@@ -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)
 }
 

+ 4 - 1
cmd/step-yubikey-init/main.go

@@ -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)
 }