| 30 | } |
| 31 | |
| 32 | func NewCmdDelete(f *cmdutil.Factory, runF func(*DeleteOptions) error) *cobra.Command { |
| 33 | opts := &DeleteOptions{ |
| 34 | IO: f.IOStreams, |
| 35 | HttpClient: f.HttpClient, |
| 36 | Config: f.Config, |
| 37 | Prompter: f.Prompter, |
| 38 | } |
| 39 | |
| 40 | cmd := &cobra.Command{ |
| 41 | Use: "delete {<number> | <url>}", |
| 42 | Short: "Delete issue", |
| 43 | Args: cobra.ExactArgs(1), |
| 44 | RunE: func(cmd *cobra.Command, args []string) error { |
| 45 | issueNumber, baseRepo, err := shared.ParseIssueFromArg(args[0]) |
| 46 | if err != nil { |
| 47 | return err |
| 48 | } |
| 49 | |
| 50 | // If the args provided the base repo then use that directly. |
| 51 | if baseRepo, present := baseRepo.Value(); present { |
| 52 | opts.BaseRepo = func() (ghrepo.Interface, error) { |
| 53 | return baseRepo, nil |
| 54 | } |
| 55 | } else { |
| 56 | // support `-R, --repo` override |
| 57 | opts.BaseRepo = f.BaseRepo |
| 58 | } |
| 59 | |
| 60 | opts.IssueNumber = issueNumber |
| 61 | |
| 62 | if runF != nil { |
| 63 | return runF(opts) |
| 64 | } |
| 65 | |
| 66 | return deleteRun(opts) |
| 67 | }, |
| 68 | } |
| 69 | |
| 70 | cmd.Flags().BoolVar(&opts.Confirmed, "confirm", false, "Confirm deletion without prompting") |
| 71 | _ = cmd.Flags().MarkDeprecated("confirm", "use `--yes` instead") |
| 72 | cmd.Flags().BoolVar(&opts.Confirmed, "yes", false, "Confirm deletion without prompting") |
| 73 | return cmd |
| 74 | } |
| 75 | |
| 76 | func deleteRun(opts *DeleteOptions) error { |
| 77 | cs := opts.IO.ColorScheme() |