| 40 | const projectVisibilityPrivate = "PRIVATE" |
| 41 | |
| 42 | func NewCmdEdit(f *cmdutil.Factory, runF func(config editConfig) error) *cobra.Command { |
| 43 | opts := editOpts{} |
| 44 | editCmd := &cobra.Command{ |
| 45 | Short: "Edit a project", |
| 46 | Use: "edit [<number>]", |
| 47 | Example: heredoc.Doc(` |
| 48 | # Edit the title of monalisa's project "1" |
| 49 | $ gh project edit 1 --owner monalisa --title "New title" |
| 50 | `), |
| 51 | Args: cobra.MaximumNArgs(1), |
| 52 | RunE: func(cmd *cobra.Command, args []string) error { |
| 53 | client, err := client.New(f) |
| 54 | if err != nil { |
| 55 | return err |
| 56 | } |
| 57 | |
| 58 | if len(args) == 1 { |
| 59 | num, err := strconv.ParseInt(args[0], 10, 32) |
| 60 | if err != nil { |
| 61 | return cmdutil.FlagErrorf("invalid number: %v", args[0]) |
| 62 | } |
| 63 | opts.number = int32(num) |
| 64 | } |
| 65 | |
| 66 | config := editConfig{ |
| 67 | client: client, |
| 68 | opts: opts, |
| 69 | io: f.IOStreams, |
| 70 | } |
| 71 | |
| 72 | if config.opts.title == "" && config.opts.shortDescription == "" && config.opts.readme == "" && config.opts.visibility == "" { |
| 73 | return fmt.Errorf("no fields to edit") |
| 74 | } |
| 75 | // allow testing of the command without actually running it |
| 76 | if runF != nil { |
| 77 | return runF(config) |
| 78 | } |
| 79 | return runEdit(config) |
| 80 | }, |
| 81 | } |
| 82 | |
| 83 | editCmd.Flags().StringVar(&opts.owner, "owner", "", "Login of the owner. Use \"@me\" for the current user.") |
| 84 | cmdutil.StringEnumFlag(editCmd, &opts.visibility, "visibility", "", "", []string{projectVisibilityPublic, projectVisibilityPrivate}, "Change project visibility") |
| 85 | editCmd.Flags().StringVar(&opts.title, "title", "", "New title for the project") |
| 86 | editCmd.Flags().StringVar(&opts.readme, "readme", "", "New readme for the project") |
| 87 | editCmd.Flags().StringVarP(&opts.shortDescription, "description", "d", "", "New description of the project") |
| 88 | cmdutil.AddFormatFlags(editCmd, &opts.exporter) |
| 89 | |
| 90 | return editCmd |
| 91 | } |
| 92 | |
| 93 | func runEdit(config editConfig) error { |
| 94 | canPrompt := config.io.CanPrompt() |