| 25 | } |
| 26 | |
| 27 | func NewCmdTransfer(f *cmdutil.Factory, runF func(*TransferOptions) error) *cobra.Command { |
| 28 | opts := TransferOptions{ |
| 29 | IO: f.IOStreams, |
| 30 | HttpClient: f.HttpClient, |
| 31 | Config: f.Config, |
| 32 | } |
| 33 | |
| 34 | cmd := &cobra.Command{ |
| 35 | Use: "transfer {<number> | <url>} <destination-repo>", |
| 36 | Short: "Transfer issue to another repository", |
| 37 | Args: cmdutil.ExactArgs(2, "issue and destination repository are required"), |
| 38 | RunE: func(cmd *cobra.Command, args []string) error { |
| 39 | issueNumber, baseRepo, err := shared.ParseIssueFromArg(args[0]) |
| 40 | if err != nil { |
| 41 | return err |
| 42 | } |
| 43 | |
| 44 | // If the args provided the base repo then use that directly. |
| 45 | if baseRepo, present := baseRepo.Value(); present { |
| 46 | opts.BaseRepo = func() (ghrepo.Interface, error) { |
| 47 | return baseRepo, nil |
| 48 | } |
| 49 | } else { |
| 50 | // support `-R, --repo` override |
| 51 | opts.BaseRepo = f.BaseRepo |
| 52 | } |
| 53 | |
| 54 | opts.IssueNumber = issueNumber |
| 55 | |
| 56 | opts.DestRepoSelector = args[1] |
| 57 | |
| 58 | if runF != nil { |
| 59 | return runF(&opts) |
| 60 | } |
| 61 | |
| 62 | return transferRun(&opts) |
| 63 | }, |
| 64 | } |
| 65 | |
| 66 | return cmd |
| 67 | } |
| 68 | |
| 69 | func transferRun(opts *TransferOptions) error { |
| 70 | httpClient, err := opts.HttpClient() |