|
1 | 1 | package delete |
2 | 2 |
|
3 | 3 | import ( |
4 | | - "errors" |
5 | 4 | "fmt" |
6 | 5 | "github.com/AlecAivazis/survey/v2" |
7 | | - "github.com/cli/cli/pkg/prompt" |
8 | | - "net/http" |
9 | | - "strconv" |
10 | | - |
11 | 6 | "github.com/cli/cli/api" |
12 | 7 | "github.com/cli/cli/internal/config" |
13 | 8 | "github.com/cli/cli/internal/ghrepo" |
14 | 9 | "github.com/cli/cli/pkg/cmd/issue/shared" |
15 | 10 | "github.com/cli/cli/pkg/cmdutil" |
16 | 11 | "github.com/cli/cli/pkg/iostreams" |
| 12 | + "github.com/cli/cli/pkg/prompt" |
17 | 13 | "github.com/spf13/cobra" |
| 14 | + "net/http" |
| 15 | + "strconv" |
18 | 16 | ) |
19 | 17 |
|
20 | 18 | type DeleteOptions struct { |
@@ -69,24 +67,23 @@ func deleteRun(opts *DeleteOptions) error { |
69 | 67 | return err |
70 | 68 | } |
71 | 69 |
|
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 | + } |
90 | 87 | } |
91 | 88 |
|
92 | 89 | err = api.IssueDelete(apiClient, baseRepo, *issue) |
|
0 commit comments