Skip to content

Commit

Permalink
Adds additional comments around optional environment configuration fo…
Browse files Browse the repository at this point in the history
…r commands
  • Loading branch information
wbreza committed Jun 5, 2024
1 parent d00940d commit 27c7e62
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cli/azd/cmd/actions/action_descriptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ type CommandGroupOptions struct {

// EnvironmentOptions contains options for the environment flag and initialization
type EnvironmentOptions struct {
// Optional should be set to true when an azd environment is optional within an azd command.
// Well known use cases for this are for `azd init` and `azd show`
Optional bool
}

Expand Down
3 changes: 3 additions & 0 deletions cli/azd/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,9 @@ func NewRootCmd(
return !descriptor.Options.DisableTelemetry
}).
UseMiddlewareWhen("environment", middleware.NewEnvironmentMiddleware, func(descriptor *actions.ActionDescriptor) bool {
// The environment middleware will only be applied to commands that have the environment flag
// AND
// on commands where an environment is always required
_, err := descriptor.Options.Command.Flags().GetString(internal.EnvironmentNameFlagName)
return err == nil && !descriptor.Options.Environment.Optional
})
Expand Down

0 comments on commit 27c7e62

Please sign in to comment.