| 26 | } |
| 27 | |
| 28 | func NewCmdReopen(f *cmdutil.Factory, runF func(*ReopenOptions) error) *cobra.Command { |
| 29 | opts := &ReopenOptions{ |
| 30 | IO: f.IOStreams, |
| 31 | HttpClient: f.HttpClient, |
| 32 | Config: f.Config, |
| 33 | } |
| 34 | |
| 35 | cmd := &cobra.Command{ |
| 36 | Use: "reopen {<number> | <url>}", |
| 37 | Short: "Reopen issue", |
| 38 | Args: cobra.ExactArgs(1), |
| 39 | RunE: func(cmd *cobra.Command, args []string) error { |
| 40 | issueNumber, baseRepo, err := shared.ParseIssueFromArg(args[0]) |
| 41 | if err != nil { |
| 42 | return err |
| 43 | } |
| 44 | |
| 45 | // If the args provided the base repo then use that directly. |
| 46 | if baseRepo, present := baseRepo.Value(); present { |
| 47 | opts.BaseRepo = func() (ghrepo.Interface, error) { |
| 48 | return baseRepo, nil |
| 49 | } |
| 50 | } else { |
| 51 | // support `-R, --repo` override |
| 52 | opts.BaseRepo = f.BaseRepo |
| 53 | } |
| 54 | |
| 55 | opts.IssueNumber = issueNumber |
| 56 | |
| 57 | if runF != nil { |
| 58 | return runF(opts) |
| 59 | } |
| 60 | return reopenRun(opts) |
| 61 | }, |
| 62 | } |
| 63 | |
| 64 | cmd.Flags().StringVarP(&opts.Comment, "comment", "c", "", "Add a reopening comment") |
| 65 | |
| 66 | return cmd |
| 67 | } |
| 68 | |
| 69 | func reopenRun(opts *ReopenOptions) error { |
| 70 | cs := opts.IO.ColorScheme() |