MCPcopy Index your code
hub / github.com/coder/coder / promptExample

Method promptExample

cli/exp_prompts.go:14–237  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

12)
13
14func (RootCmd) promptExample() *serpent.Command {
15 promptCmd := func(use string, prompt func(inv *serpent.Invocation) error, options ...serpent.Option) *serpent.Command {
16 return &serpent.Command{
17 Use: use,
18 Options: options,
19 Handler: func(inv *serpent.Invocation) error {
20 return prompt(inv)
21 },
22 }
23 }
24
25 var (
26 useSearch bool
27 useSearchOption = serpent.Option{
28 Name: "search",
29 Description: "Show the search.",
30 Required: false,
31 Flag: "search",
32 Value: serpent.BoolOf(&useSearch),
33 }
34
35 multiSelectValues []string
36 multiSelectError error
37 useThingsOption = serpent.Option{
38 Name: "things",
39 Description: "Tell me what things you want.",
40 Flag: "things",
41 Default: "",
42 Value: serpent.StringArrayOf(&multiSelectValues),
43 }
44
45 enableCustomInput bool
46 enableCustomInputOption = serpent.Option{
47 Name: "enable-custom-input",
48 Description: "Enable custom input option in multi-select.",
49 Required: false,
50 Flag: "enable-custom-input",
51 Value: serpent.BoolOf(&enableCustomInput),
52 }
53 )
54 cmd := &serpent.Command{
55 Use: "prompt-example",
56 Short: "Example of various prompt types used within coder cli.",
57 Long: "Example of various prompt types used within coder cli. " +
58 "This command exists to aid in adjusting visuals of command prompts.",
59 Handler: func(inv *serpent.Invocation) error {
60 return inv.Command.HelpHandler(inv)
61 },
62 Children: []*serpent.Command{
63 promptCmd("confirm", func(inv *serpent.Invocation) error {
64 value, err := cliui.Prompt(inv, cliui.PromptOptions{
65 Text: "Basic confirmation prompt.",
66 Default: "yes",
67 IsConfirm: true,
68 })
69 _, _ = fmt.Fprintf(inv.Stdout, "%s\n", value)
70 return err
71 }),

Callers 1

AGPLExperimentalMethod · 0.95

Calls 5

PromptFunction · 0.92
SelectFunction · 0.92
MultiSelectFunction · 0.92
RichSelectFunction · 0.92
ErrorfMethod · 0.45

Tested by

no test coverage detected