cli: warn on ambiguous 2-part environment refs#617
cli: warn on ambiguous 2-part environment refs#617LouisLau-art wants to merge 2 commits intopulumi:mainfrom
Conversation
seanyeh
left a comment
There was a problem hiding this comment.
thanks for contributing! I have a few small comments
cmd/esc/cli/env.go
Outdated
| return s | ||
| } | ||
|
|
||
| func (cmd *envCommand) warnIfAmbiguousTwoPartRef(ctx context.Context, refString string, ref environmentRef) { |
There was a problem hiding this comment.
let's not do any org checking in this method - we already do this elsewhere (look at the other comments)
This method can simply print out a warning
cmd/esc/cli/env.go
Outdated
| return | ||
| } | ||
|
|
||
| if cmd.warnedAmbiguousRefs == nil { |
There was a problem hiding this comment.
I don't think this is necessary
cmd/esc/cli/env.go
Outdated
| return ref, nil | ||
| } | ||
|
|
||
| cmd.warnIfAmbiguousTwoPartRef(ctx, refString, ref) |
There was a problem hiding this comment.
we do the org-checking below - you can move this call to inside the if existsLegacyPath { ... } check
cmd/esc/cli/env.go
Outdated
| return ref, args, nil | ||
| } | ||
|
|
||
| cmd.warnIfAmbiguousTwoPartRef(ctx, cmd.envNameFlag, ref) |
There was a problem hiding this comment.
create a new check after we calculate existsLegacyPath below, and move this call there. something like:
if existsLegacyPath {
cmd.warnIfAmbiguousTwoPartRef(...)
}
|
Thanks for the detailed review comments. I’ll push a follow-up that:
I’ll post again after the patch is up. |
|
Pushed follow-up commit
Test updates:
Validation:
|
| ) | ||
|
|
||
| if existsLegacyPath { | ||
| cmd.warnIfAmbiguousTwoPartRef(refString) |
There was a problem hiding this comment.
one last comment: we already have the same check below (see line 306) - let's move this warning there
|
Thanks for the final note — agreed. I’ll move that warning to the shared check so we only emit it once and avoid duplicate logic. |
|
Clarification: I’ll move the warning call under the shared existsLegacyPath check so the warning is emitted once from a single place. |
Fixes #613.
When a user belongs to an org named
a, a 2-part env reference likea/bcan be interpreted as either:<project>/<environment>(default org + projecta+ envb), or<org>/default/<environment>(orga+ default project + envb).This adds a warning in that case, recommending the unambiguous 3-part form
<org>/<project>/<environment>.Tests:
go test ./cmd/esc/cli -run TestCLI