-
Notifications
You must be signed in to change notification settings - Fork 233
Support bool
default in AzdMetadata
and use Confirmation
for boolean parameters
#5384
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -354,11 +354,12 @@ func (p *BicepProvider) promptForParameter( | |
defaultOption := options[0] | ||
// user can override the default value with azd metadata | ||
if azdMetadata.Default != nil { | ||
if !slices.Contains(options, *azdMetadata.Default) { | ||
defaultValStr := fmt.Sprintf("%v", azdMetadata.Default) | ||
if !slices.Contains(options, defaultValStr) { | ||
return nil, fmt.Errorf( | ||
"default value '%s' is not in the allowed values for parameter '%s'", *azdMetadata.Default, key) | ||
"default value '%s' is not in the allowed values for parameter '%s'", defaultValStr, key) | ||
} | ||
defaultOption = *azdMetadata.Default | ||
defaultOption = defaultValStr | ||
} | ||
|
||
choice, err := p.console.Select(ctx, input.ConsoleOptions{ | ||
|
@@ -372,23 +373,38 @@ func (p *BicepProvider) promptForParameter( | |
} | ||
value = (*param.AllowedValues)[choice] | ||
} else { | ||
var defaultValueForPrompt *string | ||
var defaultValueForPrompt any | ||
if azdMetadata.Default != nil { | ||
defaultValueForPrompt = azdMetadata.Default | ||
} | ||
switch paramType { | ||
case provisioning.ParameterTypeBoolean: | ||
options := []string{"False", "True"} | ||
choice, err := p.console.Select(ctx, input.ConsoleOptions{ | ||
defaultBool := true | ||
if azdMetadata.Default != nil { | ||
switch v := azdMetadata.Default.(type) { | ||
case bool: | ||
defaultBool = v | ||
case string: | ||
defaultBool = strings.EqualFold(v, "true") | ||
default: | ||
strVal := fmt.Sprintf("%v", v) | ||
defaultBool = strings.EqualFold(strVal, "true") | ||
} | ||
} | ||
msg := fmt.Sprintf("Would you like to set the '%s' infrastructure %s to %t?", key, securedParam, defaultBool) | ||
confirmValue, err := p.console.Confirm(ctx, input.ConsoleOptions{ | ||
Message: msg, | ||
Help: help, | ||
Options: options, | ||
DefaultValue: defaultValueForPrompt, | ||
DefaultValue: true, | ||
}) | ||
Comment on lines
+382
to
399
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel like the new prompt change could get a bit confusing, especially if the Bicep param has a default of Bicep: @metadata({azd: {
default: false
}})
param param1 bool New prompt: if the user inputs 'n', then the value becomes ![]() Old prompt, a bit more explicit: @SophCarp would love to get your thoughts here as well 🙂 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I prefer the way of selection (y/n) in the new prompt, but it does feel confusing due to double negative. Could we ask if users would like to set 'paraml' to true (y/N)? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmmm. By default, param1 would be false. y/n isn't the same as true/false, but rather "confirm/change". "default" should be included in the question, because otherwise a customer might be confused why they're being asked a double negative question. Maybe : ? 'param1's default value is false. Keep default value? y/n or: ? Infrastructure parameter 'param1' has a default value of 'false'. Keep default value?
> Keep (param1=false)
Change (param1=true) or: ? Confirm infrastructure parameter 'param1' = false:
> Yes (param1=false)
No (param1=true) or:
Is there more direct wording than "infrastructure parameter"? This is different from "environment variable", right? |
||
if err != nil { | ||
return nil, err | ||
} | ||
value = (options[choice] == "True") | ||
if confirmValue { | ||
value = defaultBool | ||
} else { | ||
value = !defaultBool | ||
} | ||
case provisioning.ParameterTypeNumber: | ||
userValue, err := promptWithValidation(ctx, p.console, input.ConsoleOptions{ | ||
Message: msg, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.