MCPcopy
hub / github.com/cli/cli / promptEdit

Function promptEdit

pkg/cmd/discussion/edit/edit.go:224–274  ·  view source on GitHub ↗

promptEdit runs the interactive flow, populating input with user choices. It returns a boolean indicating whether any changes were made, and an error if the process failed.

(opts *EditOptions, discussion *client.Discussion, c client.DiscussionClient, repo ghrepo.Interface, input *client.UpdateDiscussionInput)

Source from the content-addressed store, hash-verified

222// promptEdit runs the interactive flow, populating input with user choices. It returns a boolean indicating whether any
223// changes were made, and an error if the process failed.
224func promptEdit(opts *EditOptions, discussion *client.Discussion, c client.DiscussionClient, repo ghrepo.Interface, input *client.UpdateDiscussionInput) (bool, error) {
225 choices := []string{"Title", "Body", "Category"}
226 selected, err := opts.Prompter.MultiSelect("What would you like to edit?", nil, choices)
227 if err != nil {
228 return false, err
229 }
230 if len(selected) == 0 {
231 return false, nil
232 }
233
234 for _, idx := range selected {
235 switch choices[idx] {
236 case "Title":
237 title, err := opts.Prompter.Input("Title", discussion.Title)
238 if err != nil {
239 return false, err
240 }
241 if strings.TrimSpace(title) == "" {
242 return false, fmt.Errorf("title cannot be blank")
243 }
244 input.Title = &title
245
246 case "Body":
247 body, err := opts.Prompter.MarkdownEditor("Body", discussion.Body, false)
248 if err != nil {
249 return false, err
250 }
251 input.Body = &body
252
253 case "Category":
254 opts.IO.StartProgressIndicator()
255 categories, err := c.ListCategories(repo)
256 opts.IO.StopProgressIndicator()
257 if err != nil {
258 return false, err
259 }
260 names := make([]string, len(categories))
261 for i, cat := range categories {
262 names[i] = cat.Name
263 }
264 currentName := discussion.Category.Name
265 idx, err := opts.Prompter.Select("Category", currentName, names)
266 if err != nil {
267 return false, err
268 }
269 input.CategoryID = &categories[idx].ID
270 }
271 }
272
273 return true, nil
274}

Callers 1

editRunFunction · 0.85

Calls 8

MultiSelectMethod · 0.65
InputMethod · 0.65
ErrorfMethod · 0.65
MarkdownEditorMethod · 0.65
ListCategoriesMethod · 0.65
StopProgressIndicatorMethod · 0.65
SelectMethod · 0.65

Tested by

no test coverage detected