X Tutup
Skip to content

Commit 4b036f6

Browse files
Skip confirmation for non-interactive contexts
1 parent 4468a5c commit 4b036f6

File tree

1 file changed

+20
-23
lines changed

1 file changed

+20
-23
lines changed

pkg/cmd/issue/delete/delete.go

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
package delete
22

33
import (
4-
"errors"
54
"fmt"
65
"github.com/AlecAivazis/survey/v2"
7-
"github.com/cli/cli/pkg/prompt"
8-
"net/http"
9-
"strconv"
10-
116
"github.com/cli/cli/api"
127
"github.com/cli/cli/internal/config"
138
"github.com/cli/cli/internal/ghrepo"
149
"github.com/cli/cli/pkg/cmd/issue/shared"
1510
"github.com/cli/cli/pkg/cmdutil"
1611
"github.com/cli/cli/pkg/iostreams"
12+
"github.com/cli/cli/pkg/prompt"
1713
"github.com/spf13/cobra"
14+
"net/http"
15+
"strconv"
1816
)
1917

2018
type DeleteOptions struct {
@@ -69,24 +67,23 @@ func deleteRun(opts *DeleteOptions) error {
6967
return err
7068
}
7169

72-
if !opts.IO.CanPrompt() {
73-
return errors.New("deleting issues is only supported when running interactively")
74-
}
75-
76-
answer := ""
77-
err = prompt.SurveyAskOne(
78-
&survey.Input{
79-
Message: fmt.Sprintf("You're going to delete issue #%d. This action cannot be reversed. To confirm, type the issue number:", issue.Number),
80-
},
81-
&answer,
82-
)
83-
if err != nil {
84-
return err
85-
}
86-
answerInt, err := strconv.Atoi(answer)
87-
if err != nil || answerInt != issue.Number {
88-
fmt.Fprintf(opts.IO.Out, "Issue #%d was not deleted.\n", issue.Number)
89-
return nil
70+
// When executed in an interactive shell, require confirmation. Otherwise skip confirmation.
71+
if opts.IO.CanPrompt() {
72+
answer := ""
73+
err = prompt.SurveyAskOne(
74+
&survey.Input{
75+
Message: fmt.Sprintf("You're going to delete issue #%d. This action cannot be reversed. To confirm, type the issue number:", issue.Number),
76+
},
77+
&answer,
78+
)
79+
if err != nil {
80+
return err
81+
}
82+
answerInt, err := strconv.Atoi(answer)
83+
if err != nil || answerInt != issue.Number {
84+
fmt.Fprintf(opts.IO.Out, "Issue #%d was not deleted.\n", issue.Number)
85+
return nil
86+
}
9087
}
9188

9289
err = api.IssueDelete(apiClient, baseRepo, *issue)

0 commit comments

Comments
 (0)
X Tutup