Skip to content

Commit

Permalink
Fix exit after defer.
Browse files Browse the repository at this point in the history
  • Loading branch information
maraino committed Oct 7, 2021
1 parent 48549bf commit 205148a
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 6 deletions.
5 changes: 4 additions & 1 deletion cmd/step-awskms-init/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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)
}

Expand Down
10 changes: 8 additions & 2 deletions cmd/step-ca/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 4 additions & 1 deletion cmd/step-cloudkms-init/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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)
}

Expand Down
5 changes: 4 additions & 1 deletion cmd/step-pkcs11-init/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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?")
Expand Down Expand Up @@ -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) {
Expand All @@ -213,6 +215,7 @@ func fatal(err error) {
} else {
fmt.Fprintln(os.Stderr, err)
}
ui.Reset()
os.Exit(1)
}

Expand Down
5 changes: 4 additions & 1 deletion cmd/step-yubikey-init/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -123,6 +122,9 @@ func main() {
defer func() {
_ = k.Close()
}()

// Reset windows terminal
ui.Reset()
}

func fatal(err error) {
Expand All @@ -131,6 +133,7 @@ func fatal(err error) {
} else {
fmt.Fprintln(os.Stderr, err)
}
ui.Reset()
os.Exit(1)
}

Expand Down

0 comments on commit 205148a

Please sign in to comment.