| 29 | } |
| 30 | |
| 31 | func NewCmdClose(f *cmdutil.Factory, runF func(*CloseOptions) error) *cobra.Command { |
| 32 | opts := &CloseOptions{ |
| 33 | IO: f.IOStreams, |
| 34 | HttpClient: f.HttpClient, |
| 35 | GitClient: f.GitClient, |
| 36 | Branch: f.Branch, |
| 37 | } |
| 38 | |
| 39 | cmd := &cobra.Command{ |
| 40 | Use: "close {<number> | <url> | <branch>}", |
| 41 | Short: "Close a pull request", |
| 42 | Args: cmdutil.ExactArgs(1, "cannot close pull request: number, url, or branch required"), |
| 43 | RunE: func(cmd *cobra.Command, args []string) error { |
| 44 | opts.Finder = shared.NewFinder(f) |
| 45 | |
| 46 | if len(args) > 0 { |
| 47 | opts.SelectorArg = args[0] |
| 48 | } |
| 49 | |
| 50 | opts.DeleteLocalBranch = !cmd.Flags().Changed("repo") |
| 51 | |
| 52 | if runF != nil { |
| 53 | return runF(opts) |
| 54 | } |
| 55 | return closeRun(opts) |
| 56 | }, |
| 57 | } |
| 58 | |
| 59 | cmd.Flags().StringVarP(&opts.Comment, "comment", "c", "", "Leave a closing comment") |
| 60 | cmd.Flags().BoolVarP(&opts.DeleteBranch, "delete-branch", "d", false, "Delete the local and remote branch after close") |
| 61 | |
| 62 | return cmd |
| 63 | } |
| 64 | |
| 65 | func closeRun(opts *CloseOptions) error { |
| 66 | cs := opts.IO.ColorScheme() |