From 27c7e6236d5a84bf00f04631a914db98f78f651d Mon Sep 17 00:00:00 2001 From: Wallace Breza Date: Wed, 5 Jun 2024 12:07:59 -0700 Subject: [PATCH] Adds additional comments around optional environment configuration for commands --- cli/azd/cmd/actions/action_descriptor.go | 2 ++ cli/azd/cmd/root.go | 3 +++ 2 files changed, 5 insertions(+) diff --git a/cli/azd/cmd/actions/action_descriptor.go b/cli/azd/cmd/actions/action_descriptor.go index baa9605546c..286aafc0db6 100644 --- a/cli/azd/cmd/actions/action_descriptor.go +++ b/cli/azd/cmd/actions/action_descriptor.go @@ -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 } diff --git a/cli/azd/cmd/root.go b/cli/azd/cmd/root.go index d0d3289f256..3bd930d2eed 100644 --- a/cli/azd/cmd/root.go +++ b/cli/azd/cmd/root.go @@ -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 })