Skip to content

Commit

Permalink
Switch default environment to the one specified by -e if it exists
Browse files Browse the repository at this point in the history
Switch default environment to the one specified by -e if it exists
  • Loading branch information
Menghua1 committed Jan 15, 2025
1 parent 8ecd923 commit 3d81193
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
8 changes: 0 additions & 8 deletions cli/azd/cmd/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,6 @@ func (u *upAction) Run(ctx context.Context) (*actions.ActionResult, error) {
u.console.Message(ctx, output.WithGrayFormat("Note: Running custom 'up' workflow from azure.yaml"))
}

envValue := u.flags.EnvFlag.EnvironmentName
for _, step := range upWorkflow.Steps {
if envValue != "" {
stepArgs := append(step.AzdCommand.Args, "-e", envValue)
step.AzdCommand.Args = stepArgs
}
}

if err := u.workflowRunner.Run(ctx, upWorkflow); err != nil {
return nil, err
}
Expand Down
11 changes: 11 additions & 0 deletions cli/azd/pkg/environment/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,17 @@ func (m *manager) LoadOrInitInteractive(ctx context.Context, environmentName str
}
}

defaultEnvironmentName, err := m.azdContext.GetDefaultEnvironmentName()
if err != nil {
return nil, fmt.Errorf("getting default environment: %w", err)
}

if env.Name() != defaultEnvironmentName {
if err := m.azdContext.SetProjectState(azdcontext.ProjectState{DefaultEnvironment: env.Name()}); err != nil {
return nil, fmt.Errorf("saving default environment: %w", err)
}
}

return env, nil
}

Expand Down

0 comments on commit 3d81193

Please sign in to comment.