| 26 | } |
| 27 | |
| 28 | func newCmdEdit(f *cmdutil.Factory, runF func(*editOptions) error) *cobra.Command { |
| 29 | opts := editOptions{ |
| 30 | HttpClient: f.HttpClient, |
| 31 | IO: f.IOStreams, |
| 32 | } |
| 33 | |
| 34 | cmd := &cobra.Command{ |
| 35 | Use: "edit <name>", |
| 36 | Short: "Edit a label", |
| 37 | Long: heredoc.Docf(` |
| 38 | Update a label on GitHub. |
| 39 | |
| 40 | A label can be renamed using the %[1]s--name%[1]s flag. |
| 41 | |
| 42 | The label color needs to be 6 character hex value. |
| 43 | `, "`"), |
| 44 | Example: heredoc.Doc(` |
| 45 | # Update the color of the bug label |
| 46 | $ gh label edit bug --color FF0000 |
| 47 | |
| 48 | # Rename and edit the description of the bug label |
| 49 | $ gh label edit bug --name big-bug --description "Bigger than normal bug" |
| 50 | `), |
| 51 | Args: cmdutil.ExactArgs(1, "cannot update label: name argument required"), |
| 52 | RunE: func(c *cobra.Command, args []string) error { |
| 53 | opts.BaseRepo = f.BaseRepo |
| 54 | opts.Name = args[0] |
| 55 | opts.Color = strings.TrimPrefix(opts.Color, "#") |
| 56 | if opts.Description == "" && |
| 57 | opts.Color == "" && |
| 58 | opts.NewName == "" { |
| 59 | return cmdutil.FlagErrorf("specify at least one of `--color`, `--description`, or `--name`") |
| 60 | } |
| 61 | if runF != nil { |
| 62 | return runF(&opts) |
| 63 | } |
| 64 | return editRun(&opts) |
| 65 | }, |
| 66 | } |
| 67 | |
| 68 | cmd.Flags().StringVarP(&opts.Description, "description", "d", "", "Description of the label") |
| 69 | cmd.Flags().StringVarP(&opts.Color, "color", "c", "", "Color of the label") |
| 70 | cmd.Flags().StringVarP(&opts.NewName, "name", "n", "", "New name of the label") |
| 71 | |
| 72 | return cmd |
| 73 | } |
| 74 | |
| 75 | func editRun(opts *editOptions) error { |
| 76 | httpClient, err := opts.HttpClient() |