mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
fix(cli): reuse multi-select parameter values on workspace update (#22261)
Fixes three bugs that caused `coder update` to always re-prompt for multi-select (`list(string)`) parameters instead of reusing previous build values: 1. **`isValidTemplateParameterOption` failed for multi-select values** (`cli/parameterresolver.go`): It compared the entire JSON array string (e.g. `["vim","emacs"]`) against individual option values, which never matched. Now parses the JSON array and validates each element separately. 2. **`RichParameter` ignored previous build value for multi-select** (`cli/cliui/parameter.go`): The `list(string)` branch always used the template's default value instead of the `defaultValue` argument (which carries the previous build's value). Now uses `defaultValue` when available, falling back to the template default. 3. **Pre-existing crash when `list(string)` has no default value** (`cli/cliui/parameter.go`): `json.Unmarshal` on an empty string caused `unexpected end of JSON input`. Now skips unmarshaling when the default source is empty. Fixes #19956
This commit is contained in:
@@ -30,9 +30,15 @@ func RichParameter(inv *serpent.Invocation, templateVersionParameter codersdk.Te
|
||||
_, _ = fmt.Fprint(inv.Stdout, "\033[1A")
|
||||
|
||||
var defaults []string
|
||||
err = json.Unmarshal([]byte(templateVersionParameter.DefaultValue), &defaults)
|
||||
if err != nil {
|
||||
return "", err
|
||||
defaultSource := defaultValue
|
||||
if defaultSource == "" {
|
||||
defaultSource = templateVersionParameter.DefaultValue
|
||||
}
|
||||
if defaultSource != "" {
|
||||
err = json.Unmarshal([]byte(defaultSource), &defaults)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
|
||||
values, err := RichMultiSelect(inv, RichMultiSelectOptions{
|
||||
|
||||
Reference in New Issue
Block a user