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

Function NewCmdEditItem

pkg/cmd/project/item-edit/item_edit.go:76–223  ·  view source on GitHub ↗
(f *cmdutil.Factory, runF func(config editItemConfig) error)

Source from the content-addressed store, hash-verified

74}
75
76func NewCmdEditItem(f *cmdutil.Factory, runF func(config editItemConfig) error) *cobra.Command {
77 opts := editItemOpts{}
78 editItemCmd := &cobra.Command{
79 Use: "item-edit [<number>]",
80 Short: "Edit an item in a project",
81 Long: heredoc.Docf(`
82 Edit a draft issue or a project item.
83
84 The usual way to select the item and field is by name: pass the project
85 %[1]snumber%[1]s plus %[1]s--owner%[1]s, point at the item with its issue or pull
86 request %[1]s--url%[1]s, and name the field with %[1]s--field%[1]s. For single-select
87 fields, %[1]s--value%[1]s is the option name.
88
89 For scripts and machine use, you can also pass GraphQL node IDs directly with
90 %[1]s--id%[1]s, %[1]s--field-id%[1]s and %[1]s--project-id%[1]s (and, for single-select
91 fields, %[1]s--single-select-option-id%[1]s).
92
93 Note that %[1]s--url%[1]s is the issue or pull request URL, not a project URL, so its
94 owner may differ from the project's; %[1]s--owner%[1]s selects the project.
95
96 For non-draft issues, only a single field value can be updated per invocation.
97
98 Remove a project item field value with %[1]s--clear%[1]s.
99 `, "`"),
100 Example: heredoc.Doc(`
101 # Set the "Status" field to "In Progress" for an issue on monalisa's project 1
102 $ gh project item-edit 1 --owner monalisa --url https://github.com/monalisa/myproject/issues/23 --field "Status" --value "In Progress"
103
104 # Edit an item's text field value by node ID (machine / scripted use)
105 $ gh project item-edit --id <item-id> --field-id <field-id> --project-id <project-id> --text "new text"
106
107 # Clear an item's field value by node ID
108 $ gh project item-edit --id <item-id> --field-id <field-id> --project-id <project-id> --clear
109 `),
110 Args: cobra.MaximumNArgs(1),
111 RunE: func(cmd *cobra.Command, args []string) error {
112 opts.numberChanged = cmd.Flags().Changed("number")
113 opts.titleChanged = cmd.Flags().Changed("title")
114 opts.bodyChanged = cmd.Flags().Changed("body")
115 opts.valueChanged = cmd.Flags().Changed("value")
116
117 if len(args) == 1 {
118 num, err := strconv.ParseInt(args[0], 10, 32)
119 if err != nil {
120 return cmdutil.FlagErrorf("invalid number: %v", args[0])
121 }
122 opts.number32 = int32(num)
123 }
124
125 if err := cmdutil.MutuallyExclusive(
126 "only one of `--text`, `--number`, `--date`, `--single-select-option-id`, `--iteration-id` or `--value` may be used",
127 opts.text != "",
128 opts.numberChanged,
129 opts.date != "",
130 opts.singleSelectOptionID != "",
131 opts.iterationID != "",
132 opts.valueChanged,
133 ); err != nil {

Callers 1

TestNewCmdeditItemFunction · 0.85

Calls 5

FlagErrorfFunction · 0.92
MutuallyExclusiveFunction · 0.92
NewFunction · 0.92
AddFormatFlagsFunction · 0.92
runEditItemFunction · 0.85

Tested by 1

TestNewCmdeditItemFunction · 0.68