MCPcopy Index your code
hub / github.com/cli/cli / newCmdCreate

Function newCmdCreate

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

Source from the content-addressed store, hash-verified

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

Callers 2

TestNewCmdCreateFunction · 0.85
NewCmdLabelFunction · 0.85

Calls 2

ExactArgsFunction · 0.92
createRunFunction · 0.70

Tested by 1

TestNewCmdCreateFunction · 0.68