-
Notifications
You must be signed in to change notification settings - Fork 228
Confirm before automatically setting a new environment as the default #4832
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?
Conversation
Hi @@Menghua1. Thank you for your interest in helping to improve the Azure Developer CLI experience and for your contribution. We've noticed that there hasn't been recent engagement on this pull request. If this is still an active work stream, please let us know by pushing some changes or leaving a comment. Otherwise, we'll close this out in 7 days. |
cli/azd/cmd/env.go
Outdated
if shouldSetDefault { | ||
if err := en.azdCtx.SetProjectState(azdcontext.ProjectState{DefaultEnvironment: env.Name()}); err != nil { | ||
return nil, fmt.Errorf("saving default environment: %w", err) | ||
} | ||
en.console.Message(ctx, | ||
fmt.Sprintf( | ||
"The new environment '%s' has been set as the default environment.", env.Name()), | ||
) |
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.
Can we add a message if !shouldSetDefault
? To display the name of the un-changed default environment?
Also, before asking about setting as default, check if there is at least one env already there. Because if this is the first environment created with azd env new
, we should not ask and just set it as the default
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.
@vhvb1989 Thank you for your suggestion. Both the code and the PR description have been updated accordingly. Please review it.
cli/azd/pkg/environment/manager.go
Outdated
if err := m.azdContext.SetProjectState(azdcontext.ProjectState{DefaultEnvironment: env.Name()}); err != nil { | ||
return nil, fmt.Errorf("saving default environment: %w", err) | ||
m.console.Message(ctx, "") | ||
msg := fmt.Sprintf("Would you like to set the new environment '%s' as default environment?", env.Name()) |
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.
Same as before, check if the current default env name is different than env.Name()
. If it is the same we don't want to ask and re-set the same env that is already the default env
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.
@vhvb1989 The code has been updated. Additionally, to clarify: the logic added in this PR is in the if isNew code block, which is only for new environments. If env.Name()
is the same as the current default environment, it means that the environment already exists, the default environment will not change, and the part of the code I modified will not be executed.
…y un-changed default environment
Azure Dev CLI Install InstructionsInstall scriptsMacOS/Linux
bash:
pwsh:
WindowsPowerShell install
MSI install
Standalone Binary
MSI
Documentationlearn.microsoft.com documentationtitle: Azure Developer CLI reference
|
Fix issue #4800.
Before setting a new environment as the default, we prompt the user to confirm whether to set it. If this is the first environment, it is set as the default without asking. As shown in the figure below:
azd env new
command, the design is as follows:azd provision -e new-env
, the design is as follows:@rajeshkamal5050 and @vhvb1989 for notification.