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

Method addDefaultsToPrompt

internal/prompter/prompter.go:99–114  ·  view source on GitHub ↗

addDefaultsToPrompt adds default values to the prompt string.

(prompt string, defaultValues []string)

Source from the content-addressed store, hash-verified

97
98// addDefaultsToPrompt adds default values to the prompt string.
99func (p *accessiblePrompter) addDefaultsToPrompt(prompt string, defaultValues []string) string {
100 // Removing empty defaults from the slice.
101 defaultValues = slices.DeleteFunc(defaultValues, func(s string) bool {
102 return s == ""
103 })
104
105 // Pluralizing the prompt if there are multiple default values.
106 if len(defaultValues) == 1 {
107 prompt = fmt.Sprintf("%s (default: %s)", prompt, defaultValues[0])
108 } else if len(defaultValues) > 1 {
109 prompt = fmt.Sprintf("%s (defaults: %s)", prompt, strings.Join(defaultValues, ", "))
110 }
111
112 // Zero-length defaultValues means return prompt unchanged.
113 return prompt
114}
115
116func (p *accessiblePrompter) Select(prompt, defaultValue string, options []string) (int, error) {
117 var result int

Callers 4

SelectMethod · 0.95
MultiSelectMethod · 0.95
InputMethod · 0.95
ConfirmMethod · 0.95

Calls 1

JoinMethod · 0.80

Tested by

no test coverage detected