feat: add sensible defaults for azd env new / init in --no-prompt mode#7016
feat: add sensible defaults for azd env new / init in --no-prompt mode#7016rajeshkamal5050 merged 4 commits intomainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds sensible defaults for azd env new and azd init when running in --no-prompt mode, enabling non-interactive CI/CD workflows without requiring explicit environment names or subscription selections.
Changes:
- Auto-generate environment names from the working directory basename when
--no-promptis active and no name is provided - Auto-select the Azure subscription when only one exists in
--no-promptmode, with clear error messages for zero or multiple subscriptions - Remove the hard
--environmentrequirement inazd initfor non-interactive mode and auto-set new environments as default
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
cli/azd/pkg/environment/manager.go |
Add auto-name generation from cwd in ensureValidEnvironmentName() for --no-prompt mode |
cli/azd/pkg/environment/manager_test.go |
Tests for auto-name generation and CleanName edge cases |
cli/azd/cmd/init.go |
Remove the fail-fast error requiring --environment in non-interactive mode |
cli/azd/cmd/init_test.go |
Update test to verify old hard error no longer occurs |
cli/azd/pkg/prompt/prompt_service.go |
Add console field and single-subscription auto-select logic |
cli/azd/pkg/prompt/prompt_service_test.go |
Tests for subscription auto-select with in-memory config manager |
cli/azd/cmd/env.go |
Auto-set new environment as default in --no-prompt mode |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
wbreza
left a comment
There was a problem hiding this comment.
Code Review Summary
✅ What Looks Good
- Well-structured PR with clean separation of concerns across 4 distinct changes and thorough description
- Subscription auto-select logic uses a clean 0/1/many switch pattern with descriptive, actionable error messages
inMemoryUserConfigManagertest helper properly avoids disk I/O — nice improvement overconfig.NewFileConfigManager- Table-driven tests for subscription auto-select follow repo conventions with good branch coverage
Findings Summary
| Priority | Count |
|---|---|
| 🟠 High | 3 |
| 🟡 Medium | 2 |
| 🟢 Low | 2 |
| Total | 7 |
Overall Assessment: The behavioral changes are well-designed and the production code looks solid. All high findings are test-quality improvements that would strengthen confidence in the new behavior. See inline comments for details.
Co-authored-by: rajeshkamal5050 <11532743+rajeshkamal5050@users.noreply.github.com>
When --no-prompt is active: - Auto-generate environment name from working directory basename (via CleanName sanitization) when no name is provided - Auto-select Azure subscription when only one exists; check defaults.subscription config first, then fall back to auto-select - Auto-set new environment as default (skip Confirm prompt) - Remove hard error requiring --environment with --template This enables non-interactive CI/CD flows and extensions to use azd env new / azd init without implementing custom --no-prompt logic. Fixes #6934 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Use azdContext.ProjectDirectory() instead of os.Getwd() for env name generation, with fallback to os.Getwd() when azdContext is nil - Add '..' to degenerate name validation checks - Improve no-subscriptions error message to not assume unauthenticated - Document that parens are valid per EnvironmentNameRegexp in test - Clarify init test comment re: expected panics from unmocked deps Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Add IsValidEnvironmentName check after auto-generated name truncation to prevent invalid names bypassing validation (wbreza #1) - Improve init test: add featuresManager mock, set NoPromptMode, clarify panic-recovery comment (wbreza #2) - Auto-name tests now use controlled directory names and assert exact values; added truncation and special-char sub-tests (wbreza #3) - Add env_new_test.go: verify auto-set default in --no-prompt mode with multiple existing environments (wbreza #4) - Add CleanName edge cases: empty string, all-special-chars, long names (wbreza #5) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1d74220 to
603a401
Compare
Azure Dev CLI Install InstructionsInstall scriptsMacOS/Linux
bash: pwsh: WindowsPowerShell install MSI install Standalone Binary
MSI
Documentationlearn.microsoft.com documentationtitle: Azure Developer CLI reference
|
* Initial plan * Release changelog for azd 1.23.8 Co-authored-by: rajeshkamal5050 <11532743+rajeshkamal5050@users.noreply.github.com> * changelog: add PR #7016 to 1.23.8 release notes Co-authored-by: rajeshkamal5050 <11532743+rajeshkamal5050@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: rajeshkamal5050 <11532743+rajeshkamal5050@users.noreply.github.com>
#7016) * feat: add sensible defaults for azd env new / init in --no-prompt mode When --no-prompt is active: - Auto-generate environment name from working directory basename (via CleanName sanitization) when no name is provided - Auto-select Azure subscription when only one exists; check defaults.subscription config first, then fall back to auto-select - Auto-set new environment as default (skip Confirm prompt) - Remove hard error requiring --environment with --template This enables non-interactive CI/CD flows and extensions to use azd env new / azd init without implementing custom --no-prompt logic. Fixes #6934 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * address PR review feedback - Use azdContext.ProjectDirectory() instead of os.Getwd() for env name generation, with fallback to os.Getwd() when azdContext is nil - Add '..' to degenerate name validation checks - Improve no-subscriptions error message to not assume unauthenticated - Document that parens are valid per EnvironmentNameRegexp in test - Clarify init test comment re: expected panics from unmocked deps Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * ci: retrigger pipeline checks Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* Initial plan * Release changelog for azd 1.23.8 Co-authored-by: rajeshkamal5050 <11532743+rajeshkamal5050@users.noreply.github.com> * changelog: add PR #7016 to 1.23.8 release notes Co-authored-by: rajeshkamal5050 <11532743+rajeshkamal5050@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: rajeshkamal5050 <11532743+rajeshkamal5050@users.noreply.github.com>
Problem
azd env new --no-promptandazd init --no-prompt --templatefail when optional arguments (environment name, subscription) are omitted. Extensions likeazure.ai.agentsneed non-interactive init flows for CI/CD but currently must implement their own--no-promptlogic. PR #6823 was closed because the team agreed this behavior belongs in azd core, not individual extensions.Changes
1. Auto-generate environment name from working directory
When
--no-promptis active and no environment name is provided, the name defaults tofilepath.Base(cwd)sanitized via the existingCleanName()function. This is handled centrally inensureValidEnvironmentName()so bothazd env newandazd initbenefit.Before:
azd env new --no-prompt→ prompts interactively (fails in CI)After:
azd env new --no-prompt→ creates environment named after the working directory2. Auto-select subscription in non-interactive mode
When
--no-promptis active and no subscription is configured:defaults.subscriptionfrom user config (existing behavior preserved)Before: Immediately errors asking to set
defaults.subscriptionAfter: Auto-selects when unambiguous (1 subscription)
3. Remove hard
--environmentrequirement inazd initThe fail-fast error
"--environment is required when running in non-interactive mode"is removed. The environment manager now auto-generates the name, so this guard is no longer needed.4. Handle default env confirmation in
--no-promptmodeWhen creating a new environment in
--no-promptmode with multiple environments already present, theConfirm()prompt for setting it as default is skipped — the new environment is auto-set as default.Testing
manager_test.go: Auto-name generation from cwd, CleanName edge cases (7 cases)prompt_service_test.go: Subscription auto-select — 0/1/many subs, default set, default not found (5 cases)init_test.go: Updated to verify the old hard error no longer occurs (5 cases)go test ./pkg/environment/... ./pkg/prompt/... ./cmd/... -short)Files Changed
pkg/environment/manager.goensureValidEnvironmentName()pkg/environment/manager_test.gocmd/init.go--environmentrequirement in no-prompt+template modecmd/init_test.gopkg/prompt/prompt_service.goconsolefor messagingpkg/prompt/prompt_service_test.gocmd/env.goRelated