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

Function NewCmdCreateItem

pkg/cmd/project/item-create/item_create.go:37–83  ·  view source on GitHub ↗
(f *cmdutil.Factory, runF func(config createItemConfig) error)

Source from the content-addressed store, hash-verified

35}
36
37func NewCmdCreateItem(f *cmdutil.Factory, runF func(config createItemConfig) error) *cobra.Command {
38 opts := createItemOpts{}
39 createItemCmd := &cobra.Command{
40 Short: "Create a draft issue item in a project",
41 Use: "item-create [<number>]",
42 Example: heredoc.Doc(`
43 # Create a draft issue in the current user's project "1"
44 $ gh project item-create 1 --owner "@me" --title "new item" --body "new item body"
45 `),
46 Args: cobra.MaximumNArgs(1),
47 RunE: func(cmd *cobra.Command, args []string) error {
48 client, err := client.New(f)
49 if err != nil {
50 return err
51 }
52
53 if len(args) == 1 {
54 num, err := strconv.ParseInt(args[0], 10, 32)
55 if err != nil {
56 return cmdutil.FlagErrorf("invalid number: %v", args[0])
57 }
58 opts.number = int32(num)
59 }
60
61 config := createItemConfig{
62 client: client,
63 opts: opts,
64 io: f.IOStreams,
65 }
66
67 // allow testing of the command without actually running it
68 if runF != nil {
69 return runF(config)
70 }
71 return runCreateItem(config)
72 },
73 }
74
75 createItemCmd.Flags().StringVar(&opts.owner, "owner", "", "Login of the owner. Use \"@me\" for the current user.")
76 createItemCmd.Flags().StringVar(&opts.title, "title", "", "Title for the draft issue")
77 createItemCmd.Flags().StringVar(&opts.body, "body", "", "Body for the draft issue")
78 cmdutil.AddFormatFlags(createItemCmd, &opts.exporter)
79
80 _ = createItemCmd.MarkFlagRequired("title")
81
82 return createItemCmd
83}
84
85func runCreateItem(config createItemConfig) error {
86 canPrompt := config.io.CanPrompt()

Callers 1

TestNewCmdCreateItemFunction · 0.85

Calls 4

NewFunction · 0.92
FlagErrorfFunction · 0.92
AddFormatFlagsFunction · 0.92
runCreateItemFunction · 0.85

Tested by 1

TestNewCmdCreateItemFunction · 0.68