mirror of
https://github.com/coder/coder.git
synced 2026-06-02 20:48:20 +00:00
fix(cli/cliui): apply defaults when rendering select prompts (#22093)
The `--parameter-default` value is now used to pre-select the default option for a coder parameter with option blocks when prompting interactively in CLI. Related to: https://github.com/coder/coder/issues/22078
This commit is contained in:
@@ -123,6 +123,10 @@ func Select(inv *serpent.Invocation, opts SelectOptions) (string, error) {
|
||||
initialModel.height = defaultSelectModelHeight
|
||||
}
|
||||
|
||||
if idx := slices.Index(opts.Options, opts.Default); idx >= 0 {
|
||||
initialModel.cursor = idx
|
||||
}
|
||||
|
||||
initialModel.search.Prompt = ""
|
||||
initialModel.search.Focus()
|
||||
|
||||
|
||||
+3
-3
@@ -109,13 +109,13 @@ func (RootCmd) promptExample() *serpent.Command {
|
||||
Options: []string{
|
||||
"Blue", "Green", "Yellow", "Red", "Something else",
|
||||
},
|
||||
Default: "",
|
||||
Default: "Green",
|
||||
Message: "Select your favorite color:",
|
||||
Size: 5,
|
||||
HideSearch: !useSearch,
|
||||
})
|
||||
if value == "Something else" {
|
||||
_, _ = fmt.Fprint(inv.Stdout, "I would have picked blue.\n")
|
||||
_, _ = fmt.Fprint(inv.Stdout, "I would have picked green.\n")
|
||||
} else {
|
||||
_, _ = fmt.Fprintf(inv.Stdout, "%s is a nice color.\n", value)
|
||||
}
|
||||
@@ -128,7 +128,7 @@ func (RootCmd) promptExample() *serpent.Command {
|
||||
Options: []string{
|
||||
"Car", "Bike", "Plane", "Boat", "Train",
|
||||
},
|
||||
Default: "Car",
|
||||
Default: "Bike",
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user