| 27 | } |
| 28 | |
| 29 | func NewCmdClose(f *cmdutil.Factory, runF func(*CloseOptions) error) *cobra.Command { |
| 30 | opts := &CloseOptions{ |
| 31 | IO: f.IOStreams, |
| 32 | HttpClient: f.HttpClient, |
| 33 | } |
| 34 | |
| 35 | cmd := &cobra.Command{ |
| 36 | Use: "close {<number> | <url>}", |
| 37 | Short: "Close issue", |
| 38 | Example: heredoc.Doc(` |
| 39 | # Close issue |
| 40 | $ gh issue close 123 |
| 41 | |
| 42 | # Close issue and add a closing comment |
| 43 | $ gh issue close 123 --comment "Closing this issue" |
| 44 | |
| 45 | # Close issue as a duplicate of issue #456 |
| 46 | $ gh issue close 123 --duplicate-of 456 |
| 47 | |
| 48 | # Close issue as not planned |
| 49 | $ gh issue close 123 --reason "not planned" |
| 50 | `), |
| 51 | Args: cobra.ExactArgs(1), |
| 52 | RunE: func(cmd *cobra.Command, args []string) error { |
| 53 | issueNumber, baseRepo, err := shared.ParseIssueFromArg(args[0]) |
| 54 | if err != nil { |
| 55 | return err |
| 56 | } |
| 57 | |
| 58 | // If the args provided the base repo then use that directly. |
| 59 | if baseRepo, present := baseRepo.Value(); present { |
| 60 | opts.BaseRepo = func() (ghrepo.Interface, error) { |
| 61 | return baseRepo, nil |
| 62 | } |
| 63 | } else { |
| 64 | // support `-R, --repo` override |
| 65 | opts.BaseRepo = f.BaseRepo |
| 66 | } |
| 67 | |
| 68 | opts.IssueNumber = issueNumber |
| 69 | if opts.DuplicateOf != "" { |
| 70 | if opts.Reason == "" { |
| 71 | opts.Reason = "duplicate" |
| 72 | } else if opts.Reason != "duplicate" { |
| 73 | return cmdutil.FlagErrorf("`--duplicate-of` can only be used with `--reason duplicate`") |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | if runF != nil { |
| 78 | return runF(opts) |
| 79 | } |
| 80 | return closeRun(opts) |
| 81 | }, |
| 82 | } |
| 83 | |
| 84 | cmd.Flags().StringVarP(&opts.Comment, "comment", "c", "", "Leave a closing comment") |
| 85 | cmdutil.StringEnumFlag(cmd, &opts.Reason, "reason", "r", "", []string{"completed", "not planned", "duplicate"}, "Reason for closing") |
| 86 | cmd.Flags().StringVar(&opts.DuplicateOf, "duplicate-of", "", "Mark as duplicate of another issue by number or URL") |