MCPcopy Index your code
hub / github.com/rilldata/rill / SelectPromptWithDescriptions

Function SelectPromptWithDescriptions

cli/pkg/cmdutil/prompt.go:30–52  ·  view source on GitHub ↗

SelectPromptWithDescriptions is like SelectPrompt but shows a description next to each option. The descriptions slice must be the same length as options.

(msg string, options, descriptions []string, def string)

Source from the content-addressed store, hash-verified

28// SelectPromptWithDescriptions is like SelectPrompt but shows a description next to each option.
29// The descriptions slice must be the same length as options.
30func SelectPromptWithDescriptions(msg string, options, descriptions []string, def string) (string, error) {
31 if len(options) != len(descriptions) {
32 return "", fmt.Errorf("options and descriptions must be the same length")
33 }
34
35 prompt := &survey.Select{
36 Message: msg,
37 Options: options,
38 Description: func(value string, index int) string {
39 return descriptions[index]
40 },
41 }
42
43 if slices.Contains(options, def) {
44 prompt.Default = def
45 }
46
47 result := ""
48 if err := survey.AskOne(prompt, &result); err != nil {
49 return "", fmt.Errorf("prompt failed: %w", err)
50 }
51 return result, nil
52}
53
54// ConfirmPrompt asks the user to confirm an action.
55// It returns nil if the user confirms and an error if the user declines (or the prompt fails).

Callers

nothing calls this directly

Calls 2

ContainsMethod · 0.80
ErrorfMethod · 0.65

Tested by

no test coverage detected