MCPcopy Create free account
hub / github.com/cli/cli / newCmdCreate

Function newCmdCreate

pkg/cmd/label/create.go:52–90  ·  view source on GitHub ↗
(f *cmdutil.Factory, runF func(*createOptions) error)

Source from the content-addressed store, hash-verified

50}
51
52func newCmdCreate(f *cmdutil.Factory, runF func(*createOptions) error) *cobra.Command {
53 opts := createOptions{
54 HttpClient: f.HttpClient,
55 IO: f.IOStreams,
56 }
57
58 cmd := &cobra.Command{
59 Use: "create <name>",
60 Short: "Create a new label",
61 Long: heredoc.Docf(`
62 Create a new label on GitHub, or update an existing one with %[1]s--force%[1]s.
63
64 Must specify name for the label. The description and color are optional.
65 If a color isn't provided, a random one will be chosen.
66
67 The label color needs to be 6 character hex value.
68 `, "`"),
69 Example: heredoc.Doc(`
70 # Create new bug label
71 $ gh label create bug --description "Something isn't working" --color E99695
72 `),
73 Args: cmdutil.ExactArgs(1, "cannot create label: name argument required"),
74 RunE: func(c *cobra.Command, args []string) error {
75 opts.BaseRepo = f.BaseRepo
76 opts.Name = args[0]
77 opts.Color = strings.TrimPrefix(opts.Color, "#")
78 if runF != nil {
79 return runF(&opts)
80 }
81 return createRun(&opts)
82 },
83 }
84
85 cmd.Flags().StringVarP(&opts.Description, "description", "d", "", "Description of the label")
86 cmd.Flags().StringVarP(&opts.Color, "color", "c", "", "Color of the label")
87 cmd.Flags().BoolVarP(&opts.Force, "force", "f", false, "Update the label color and description if label already exists")
88
89 return cmd
90}
91
92var errLabelAlreadyExists = errors.New("label already exists")
93

Callers 2

TestNewCmdCreateFunction · 0.85
NewCmdLabelFunction · 0.85

Calls 2

ExactArgsFunction · 0.92
createRunFunction · 0.70

Tested by 1

TestNewCmdCreateFunction · 0.68