Skip to content

Commit 3d81193

Browse files
committed
Switch default environment to the one specified by -e if it exists
Switch default environment to the one specified by -e if it exists
1 parent 8ecd923 commit 3d81193

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

cli/azd/cmd/up.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -130,14 +130,6 @@ func (u *upAction) Run(ctx context.Context) (*actions.ActionResult, error) {
130130
u.console.Message(ctx, output.WithGrayFormat("Note: Running custom 'up' workflow from azure.yaml"))
131131
}
132132

133-
envValue := u.flags.EnvFlag.EnvironmentName
134-
for _, step := range upWorkflow.Steps {
135-
if envValue != "" {
136-
stepArgs := append(step.AzdCommand.Args, "-e", envValue)
137-
step.AzdCommand.Args = stepArgs
138-
}
139-
}
140-
141133
if err := u.workflowRunner.Run(ctx, upWorkflow); err != nil {
142134
return nil, err
143135
}

cli/azd/pkg/environment/manager.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,17 @@ func (m *manager) LoadOrInitInteractive(ctx context.Context, environmentName str
177177
}
178178
}
179179

180+
defaultEnvironmentName, err := m.azdContext.GetDefaultEnvironmentName()
181+
if err != nil {
182+
return nil, fmt.Errorf("getting default environment: %w", err)
183+
}
184+
185+
if env.Name() != defaultEnvironmentName {
186+
if err := m.azdContext.SetProjectState(azdcontext.ProjectState{DefaultEnvironment: env.Name()}); err != nil {
187+
return nil, fmt.Errorf("saving default environment: %w", err)
188+
}
189+
}
190+
180191
return env, nil
181192
}
182193

0 commit comments

Comments
 (0)