Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

azd env set add warning #4547

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions cli/azd/cmd/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"errors"
"fmt"
"io"
"strings"

"github.com/azure/azure-dev/cli/azd/cmd/actions"
"github.com/azure/azure-dev/cli/azd/internal"
Expand Down Expand Up @@ -142,6 +143,8 @@ func newEnvSetAction(

func (e *envSetAction) Run(ctx context.Context) (*actions.ActionResult, error) {
e.env.DotenvSet(e.args[0], e.args[1])
// Check for case-insensitive key conflicts
checkKeyCaseConflict(e.env, e.args[0])

if err := e.envManager.Save(ctx, e.env); err != nil {
return nil, fmt.Errorf("saving environment: %w", err)
Expand All @@ -150,6 +153,24 @@ func (e *envSetAction) Run(ctx context.Context) (*actions.ActionResult, error) {
return nil, nil
}

// Check if there are any case-insensitive match conflicts in the environment name
func checkKeyCaseConflict(env *environment.Environment, key string) {
lowerKey := strings.ToLower(key)

for existingKey := range env.Dotenv() {
if existingKey == key {
continue
}

if strings.ToLower(existingKey) == lowerKey {
fmt.Printf(
"WARN: The environment variable '%v' already exists in the .env file with a different case.\n",
existingKey)
return
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please ensure warning messages are consistent with other warnings in the system. Messages should read "WARNING: [Message]" in Yellow by using our output.WithWarningFormat(...) helper function.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wbreza I have updated based on suggestions, please re-review.

}
}

func newEnvSelectCmd() *cobra.Command {
return &cobra.Command{
Use: "select <environment>",
Expand Down
Loading