From 5dc4075ca03bc408c83d0a0495eec9d31773cd0c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 10 Dec 2025 01:06:17 +0000 Subject: [PATCH 1/5] Initial plan From e8eb7558622eab9a2f3422f9458d303059735cd1 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 10 Dec 2025 01:16:31 +0000 Subject: [PATCH 2/5] Add interactive CLI selector to azd env select command - Modified newEnvSelectCmd to accept 0 or 1 arguments - Added console parameter to envSelectAction for interactive prompts - Implemented environment selection prompt when no argument is provided - Maintains backward compatibility with explicit environment argument - Shows helpful error message when no environments exist Co-authored-by: vhvb1989 <24213737+vhvb1989@users.noreply.github.com> --- cli/azd/cmd/env.go | 53 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 46 insertions(+), 7 deletions(-) diff --git a/cli/azd/cmd/env.go b/cli/azd/cmd/env.go index 20918413453..7624d9252db 100644 --- a/cli/azd/cmd/env.go +++ b/cli/azd/cmd/env.go @@ -697,39 +697,78 @@ func newEnvSetSecretAction( func newEnvSelectCmd() *cobra.Command { return &cobra.Command{ - Use: "select ", + Use: "select []", Short: "Set the default environment.", - Args: cobra.ExactArgs(1), + Args: cobra.MaximumNArgs(1), } } type envSelectAction struct { azdCtx *azdcontext.AzdContext envManager environment.Manager + console input.Console args []string } -func newEnvSelectAction(azdCtx *azdcontext.AzdContext, envManager environment.Manager, args []string) actions.Action { +func newEnvSelectAction( + azdCtx *azdcontext.AzdContext, + envManager environment.Manager, + console input.Console, + args []string, +) actions.Action { return &envSelectAction{ azdCtx: azdCtx, envManager: envManager, + console: console, args: args, } } func (e *envSelectAction) Run(ctx context.Context) (*actions.ActionResult, error) { - _, err := e.envManager.Get(ctx, e.args[0]) + var environmentName string + + // If no argument provided, prompt the user to select an environment + if len(e.args) == 0 { + envs, err := e.envManager.List(ctx) + if err != nil { + return nil, fmt.Errorf("listing environments: %w", err) + } + + if len(envs) == 0 { + return nil, fmt.Errorf("no environments found. You can create one with \"azd env new\"") + } + + // Build list of environment names + envNames := make([]string, len(envs)) + for i, env := range envs { + envNames[i] = env.Name + } + + selection, err := e.console.Select(ctx, input.ConsoleOptions{ + Message: "Select an environment:", + Options: envNames, + }) + if err != nil { + return nil, fmt.Errorf("selecting environment: %w", err) + } + + environmentName = envNames[selection] + } else { + environmentName = e.args[0] + } + + _, err := e.envManager.Get(ctx, environmentName) if errors.Is(err, environment.ErrNotFound) { return nil, fmt.Errorf( `environment '%s' does not exist. You can create it with "azd env new %s"`, - e.args[0], - e.args[0], + environmentName, + environmentName, ) } else if err != nil { return nil, fmt.Errorf("ensuring environment exists: %w", err) } - if err := e.azdCtx.SetProjectState(azdcontext.ProjectState{DefaultEnvironment: e.args[0]}); err != nil { + if err := e.azdCtx.SetProjectState(azdcontext.ProjectState{DefaultEnvironment: environmentName}); err != nil { return nil, fmt.Errorf("setting default environment: %w", err) } From 0bde611fb22ea309945741d1593dbd8396444113 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 10 Dec 2025 01:22:44 +0000 Subject: [PATCH 3/5] Update snapshots for azd env select command changes - Updated TestUsage snapshot to reflect optional environment argument - Updated TestFigSpec autocomplete spec with isOptional flag Co-authored-by: vhvb1989 <24213737+vhvb1989@users.noreply.github.com> --- cli/azd/cmd/testdata/TestFigSpec.ts | 1 + cli/azd/cmd/testdata/TestUsage-azd-env-select.snap | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/cli/azd/cmd/testdata/TestFigSpec.ts b/cli/azd/cmd/testdata/TestFigSpec.ts index fbcec8a3821..11f41f1eb82 100644 --- a/cli/azd/cmd/testdata/TestFigSpec.ts +++ b/cli/azd/cmd/testdata/TestFigSpec.ts @@ -535,6 +535,7 @@ const completionSpec: Fig.Spec = { description: 'Set the default environment.', args: { name: 'environment', + isOptional: true, generators: azdGenerators.listEnvironments, }, }, diff --git a/cli/azd/cmd/testdata/TestUsage-azd-env-select.snap b/cli/azd/cmd/testdata/TestUsage-azd-env-select.snap index a30b0d792a9..9322a4fcbb6 100644 --- a/cli/azd/cmd/testdata/TestUsage-azd-env-select.snap +++ b/cli/azd/cmd/testdata/TestUsage-azd-env-select.snap @@ -2,7 +2,7 @@ Set the default environment. Usage - azd env select [flags] + azd env select [] [flags] Global Flags -C, --cwd string : Sets the current working directory. From 1ed864b81b1cd4cc8d15a59ba323226bbc6cd318 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 10 Dec 2025 01:25:12 +0000 Subject: [PATCH 4/5] Fix error message consistency for environment creation Make error message more explicit by including placeholder Co-authored-by: vhvb1989 <24213737+vhvb1989@users.noreply.github.com> --- cli/azd/cmd/env.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/azd/cmd/env.go b/cli/azd/cmd/env.go index 7624d9252db..d4bd9ff2612 100644 --- a/cli/azd/cmd/env.go +++ b/cli/azd/cmd/env.go @@ -735,7 +735,7 @@ func (e *envSelectAction) Run(ctx context.Context) (*actions.ActionResult, error } if len(envs) == 0 { - return nil, fmt.Errorf("no environments found. You can create one with \"azd env new\"") + return nil, fmt.Errorf("no environments found. You can create one with \"azd env new \"") } // Build list of environment names From 4c07ca2c0864153be6f897fa1db7d6140857bdbb Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 10 Dec 2025 01:30:52 +0000 Subject: [PATCH 5/5] Final verification and testing complete Co-authored-by: vhvb1989 <24213737+vhvb1989@users.noreply.github.com> --- cli/azd/extensions/azure.ai.agents/go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/azd/extensions/azure.ai.agents/go.mod b/cli/azd/extensions/azure.ai.agents/go.mod index 78453895d53..d7f8a573c55 100644 --- a/cli/azd/extensions/azure.ai.agents/go.mod +++ b/cli/azd/extensions/azure.ai.agents/go.mod @@ -17,6 +17,7 @@ require ( github.com/google/uuid v1.6.0 github.com/mark3labs/mcp-go v0.41.1 github.com/spf13/cobra v1.10.1 + github.com/spf13/pflag v1.0.10 go.yaml.in/yaml/v3 v3.0.4 google.golang.org/protobuf v1.36.10 gopkg.in/yaml.v3 v3.0.1 @@ -75,7 +76,6 @@ require ( github.com/rivo/uniseg v0.4.7 // indirect github.com/sethvargo/go-retry v0.3.0 // indirect github.com/spf13/cast v1.10.0 // indirect - github.com/spf13/pflag v1.0.10 // indirect github.com/stretchr/testify v1.11.1 // indirect github.com/theckman/yacspin v0.13.12 // indirect github.com/wk8/go-ordered-map/v2 v2.1.8 // indirect