Skip to content

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Menghua1
Copy link
Member

@Menghua1 Menghua1 commented Jun 20, 2025

Fix #5276. This PR includes the following changes:

  1. Change the default field type in the AzdMetadata structure to any to support both bool and string.
  2. For bool parameters, use Confirmation (Yes/No options) instead of survey.Select.

@rajeshkamal5050 and @vhvb1989 for notification.

Copy link
Collaborator

@kristenwomack kristenwomack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - @vhvb1989, will adding this flexibility cause any unintended issues elsewhere?

@kristenwomack
Copy link
Collaborator

FYI @alexwolfmsft for updating the docs

Comment on lines +194 to +196
defaultStr := fmt.Sprintf("%v", azdMetadata.Default)
tmp := defaultStr
return &tmp
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
defaultStr := fmt.Sprintf("%v", azdMetadata.Default)
tmp := defaultStr
return &tmp
defaultStr := fmt.Sprintf("%v", azdMetadata.Default)
return &defaultStr

Comment on lines +382 to 399
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,
})
Copy link
Contributor

Choose a reason for hiding this comment

The 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 false because of the double negative.

Bicep:

@metadata({azd: {
  default: false
}})
param param1 bool

New prompt: if the user inputs 'n', then the value becomes true in this case:

image

Old prompt, a bit more explicit:
image

@SophCarp would love to get your thoughts here as well 🙂

Copy link
Contributor

Choose a reason for hiding this comment

The 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)?

Copy link
Collaborator

@SophCarp SophCarp Jun 20, 2025

Choose a reason for hiding this comment

The 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:

? Confirm infrastructure parameter 'param1' = false: y/n

Is there more direct wording than "infrastructure parameter"? This is different from "environment variable", right?

@vhvb1989
Copy link
Member

used #5386 to fix the prompt regressions on bool/int with no defaults.

@Menghua1 , let's use this PR for only adding support for types in the default azd metadata field.
Please rebase on top of main and use this PR to allow something like

image

Instead of the current:

image

Similar for int params, we should support numbers instead of asking for string only. It's not a high priority, so no need to rush.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Issue]ERROR: prompting for value: default value of select must be an int or string
6 participants