@@ -177,10 +177,19 @@ func registerCommonDependencies(container *ioc.NestedContainer) {
177
177
// semantics to follow.
178
178
envValue , err := cmd .Flags ().GetString (internal .EnvironmentNameFlagName )
179
179
if err != nil {
180
- log .Printf ("'%s'command asked for envFlag, but envFlag was not included in cmd.Flags()." , cmd .CommandPath ())
180
+ log .Printf ("'%s' command asked for envFlag, but envFlag was not included in cmd.Flags()." , cmd .CommandPath ())
181
181
envValue = ""
182
182
}
183
183
184
+ envTypeValue , err := cmd .Flags ().GetString (internal .EnvironmentTypeFlagName )
185
+ if err != nil {
186
+ log .Printf (
187
+ "'%s' command asked for envTypeFlag, but envTypeFlag was not included in cmd.Flags()." ,
188
+ cmd .CommandPath (),
189
+ )
190
+ envTypeValue = ""
191
+ }
192
+
184
193
if envValue == "" {
185
194
// If no explicit environment flag was set, but one was provided
186
195
// in the context, use that instead.
@@ -190,7 +199,10 @@ func registerCommonDependencies(container *ioc.NestedContainer) {
190
199
}
191
200
}
192
201
193
- return internal.EnvFlag {EnvironmentName : envValue }
202
+ return internal.EnvFlag {
203
+ EnvironmentName : envValue ,
204
+ EnvironmentType : envTypeValue ,
205
+ }
194
206
})
195
207
196
208
container .MustRegisterSingleton (func (cmd * cobra.Command ) CmdAnnotations {
@@ -229,9 +241,10 @@ func registerCommonDependencies(container *ioc.NestedContainer) {
229
241
}
230
242
231
243
environmentName := envFlags .EnvironmentName
244
+ environmentType := envFlags .EnvironmentType
232
245
var err error
233
246
234
- env , err := envManager .LoadOrInitInteractive (ctx , environmentName )
247
+ env , err := envManager .LoadOrInitInteractiveWithType (ctx , environmentName , environmentType )
235
248
if err != nil {
236
249
return nil , fmt .Errorf ("loading environment: %w" , err )
237
250
}
@@ -382,14 +395,23 @@ func registerCommonDependencies(container *ioc.NestedContainer) {
382
395
func (
383
396
ctx context.Context ,
384
397
lazyAzdContext * lazy.Lazy [* azdcontext.AzdContext ],
398
+ envFlags internal.EnvFlag ,
385
399
) * lazy.Lazy [* project.ProjectConfig ] {
386
400
return lazy .NewLazy (func () (* project.ProjectConfig , error ) {
387
401
azdCtx , err := lazyAzdContext .GetValue ()
388
402
if err != nil {
389
403
return nil , err
390
404
}
391
405
392
- projectConfig , err := project .Load (ctx , azdCtx .ProjectPath ())
406
+ // Use environment-specific project path when an environment is specified
407
+ var projectPath string
408
+ if envFlags .EnvironmentName != "" {
409
+ projectPath = azdCtx .ProjectPathForEnvironment (envFlags .EnvironmentName )
410
+ } else {
411
+ projectPath = azdCtx .ProjectPath ()
412
+ }
413
+
414
+ projectConfig , err := project .Load (ctx , projectPath )
393
415
if err != nil {
394
416
return nil , err
395
417
}
@@ -405,6 +427,7 @@ func registerCommonDependencies(container *ioc.NestedContainer) {
405
427
lazyProjectConfig * lazy.Lazy [* project.ProjectConfig ],
406
428
lazyAzdContext * lazy.Lazy [* azdcontext.AzdContext ],
407
429
lazyLocalEnvStore * lazy.Lazy [environment.LocalDataStore ],
430
+ envFlags internal.EnvFlag ,
408
431
) (* cloud.Cloud , error ) {
409
432
410
433
// Precedence for cloud configuration:
@@ -424,8 +447,15 @@ func registerCommonDependencies(container *ioc.NestedContainer) {
424
447
localEnvStore , _ := lazyLocalEnvStore .GetValue ()
425
448
if azdCtx , err := lazyAzdContext .GetValue (); err == nil {
426
449
if azdCtx != nil && localEnvStore != nil {
427
- if defaultEnvName , err := azdCtx .GetDefaultEnvironmentName (); err == nil {
428
- if env , err := localEnvStore .Get (ctx , defaultEnvName ); err == nil {
450
+ var envName string
451
+ if envFlags .EnvironmentName != "" {
452
+ envName = envFlags .EnvironmentName
453
+ } else if defaultEnvName , err := azdCtx .GetDefaultEnvironmentName (); err == nil {
454
+ envName = defaultEnvName
455
+ }
456
+
457
+ if envName != "" {
458
+ if env , err := localEnvStore .Get (ctx , envName ); err == nil {
429
459
if cloudConfigurationNode , exists := env .Config .Get (cloud .ConfigPath ); exists {
430
460
if value , err := cloud .ParseCloudConfig (cloudConfigurationNode ); err == nil {
431
461
cloudConfig , err := cloud .NewCloud (value )
@@ -438,7 +468,7 @@ func registerCommonDependencies(container *ioc.NestedContainer) {
438
468
Suggestion : fmt .Sprintf (
439
469
"Set the cloud configuration by editing the 'cloud' node in the config.json " +
440
470
"file for the %s environment\n %s" ,
441
- defaultEnvName ,
471
+ envName ,
442
472
validClouds ,
443
473
),
444
474
}
0 commit comments