Avoid the issue/pr recovery mechanism handling Ctrl-C keypress in prompts
Either InterruptErr or SilentErr will be present when the user has chosen "Cancel" or pressed Ctrl-C in prompts. We don't want the recovery mechanism to kick in these cases because the cancellation was likely willingly initiated by the user.
This commit is contained in:
parent
fff051468e
commit
3efa764305
3 changed files with 12 additions and 4 deletions
|
|
@ -249,8 +249,8 @@ func createRun(opts *CreateOptions) (err error) {
|
|||
|
||||
if action == prShared.CancelAction {
|
||||
fmt.Fprintln(opts.IO.ErrOut, "Discarding.")
|
||||
err = nil // avoid triggering PreserveInput
|
||||
return cmdutil.SilentError
|
||||
err = cmdutil.SilentError
|
||||
return
|
||||
}
|
||||
} else {
|
||||
if tb.Title == "" {
|
||||
|
|
|
|||
|
|
@ -299,8 +299,8 @@ func createRun(opts *CreateOptions) (err error) {
|
|||
|
||||
if action == shared.CancelAction {
|
||||
fmt.Fprintln(opts.IO.ErrOut, "Discarding.")
|
||||
err = nil // avoid triggering PreserveInput
|
||||
return cmdutil.SilentError
|
||||
err = cmdutil.SilentError
|
||||
return
|
||||
}
|
||||
|
||||
err = handlePush(*opts, *ctx)
|
||||
|
|
|
|||
|
|
@ -2,9 +2,12 @@ package shared
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/AlecAivazis/survey/v2/terminal"
|
||||
"github.com/cli/cli/pkg/cmdutil"
|
||||
"github.com/cli/cli/pkg/iostreams"
|
||||
)
|
||||
|
||||
|
|
@ -18,6 +21,11 @@ func PreserveInput(io *iostreams.IOStreams, state *IssueMetadataState, createErr
|
|||
return
|
||||
}
|
||||
|
||||
if errors.Is(*createErr, cmdutil.SilentError) || errors.Is(*createErr, terminal.InterruptErr) {
|
||||
// these errors are user-initiated cancellations
|
||||
return
|
||||
}
|
||||
|
||||
out := io.ErrOut
|
||||
|
||||
// this extra newline guards against appending to the end of a survey line
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue