| 35 | } |
| 36 | |
| 37 | func NewCmdClose(f *cmdutil.Factory, runF func(config closeConfig) error) *cobra.Command { |
| 38 | opts := closeOpts{} |
| 39 | closeCmd := &cobra.Command{ |
| 40 | Short: "Close a project", |
| 41 | Use: "close [<number>]", |
| 42 | Example: heredoc.Doc(` |
| 43 | # Close project "1" owned by monalisa |
| 44 | $ gh project close 1 --owner monalisa |
| 45 | |
| 46 | # Reopen closed project "1" owned by github |
| 47 | $ gh project close 1 --owner github --undo |
| 48 | `), |
| 49 | Args: cobra.MaximumNArgs(1), |
| 50 | RunE: func(cmd *cobra.Command, args []string) error { |
| 51 | client, err := client.New(f) |
| 52 | if err != nil { |
| 53 | return err |
| 54 | } |
| 55 | |
| 56 | if len(args) == 1 { |
| 57 | num, err := strconv.ParseInt(args[0], 10, 32) |
| 58 | if err != nil { |
| 59 | return cmdutil.FlagErrorf("invalid number: %v", args[0]) |
| 60 | } |
| 61 | opts.number = int32(num) |
| 62 | } |
| 63 | |
| 64 | config := closeConfig{ |
| 65 | io: f.IOStreams, |
| 66 | client: client, |
| 67 | opts: opts, |
| 68 | } |
| 69 | |
| 70 | // allow testing of the command without actually running it |
| 71 | if runF != nil { |
| 72 | return runF(config) |
| 73 | } |
| 74 | return runClose(config) |
| 75 | }, |
| 76 | } |
| 77 | |
| 78 | closeCmd.Flags().StringVar(&opts.owner, "owner", "", "Login of the owner. Use \"@me\" for the current user.") |
| 79 | closeCmd.Flags().BoolVar(&opts.reopen, "undo", false, "Reopen a closed project") |
| 80 | cmdutil.AddFormatFlags(closeCmd, &opts.exporter) |
| 81 | |
| 82 | return closeCmd |
| 83 | } |
| 84 | |
| 85 | func runClose(config closeConfig) error { |
| 86 | canPrompt := config.io.CanPrompt() |