Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion cmd/esc/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1203,7 +1203,8 @@ func (c *testPulumiClient) EnvironmentExists(
projectName string,
envName string,
) (bool, error) {
return false, nil
_, ok := c.environments[path.Join(orgName, projectName, envName)]
return ok, nil
}

func (c *testPulumiClient) CreateEnvironmentOpenRequest(
Expand Down
16 changes: 16 additions & 0 deletions cmd/esc/cli/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,14 @@ func (r *environmentRef) String() string {
return s
}

func (cmd *envCommand) warnIfAmbiguousTwoPartRef(refString string) {
fmt.Fprintf(
cmd.esc.stderr,
"warning: environment reference %q is ambiguous (could be <project>/<environment> or <org>/default/<environment>); prefer <org>/<project>/<environment>.\n",
refString,
)
}

func (cmd *envCommand) parseRef(refStr string) environmentRef {
var orgName, projectName, envNameAndVersion string

Expand Down Expand Up @@ -223,6 +231,10 @@ func (cmd *envCommand) getNewEnvRef(
}
}

if existsLegacyPath {
cmd.warnIfAmbiguousTwoPartRef(cmd.envNameFlag)
}

if !existsProject && existsLegacyPath {
return legacyRef, args, nil
}
Expand Down Expand Up @@ -279,6 +291,10 @@ func (cmd *envCommand) getExistingEnvRefWithRelative(
legacyRef.envName,
)

if existsLegacyPath {
cmd.warnIfAmbiguousTwoPartRef(refString)
Copy link
Contributor

Choose a reason for hiding this comment

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

one last comment: we already have the same check below (see line 306) - let's move this warning there

}

// Require unambiguous path if both paths exist
if exists && existsLegacyPath {
return ref, ambiguousIdentifierError{
Expand Down
15 changes: 15 additions & 0 deletions cmd/esc/cli/testdata/env-ambiguous-two-part-warning.yaml
Copy link
Contributor

Choose a reason for hiding this comment

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

thanks for adding a test!

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
run: |
esc env get test-org/env --definition
environments:
test-org/default/env:
values:
string: esc

---
> esc env get test-org/env --definition
values:
string: esc

---
> esc env get test-org/env --definition
warning: environment reference "test-org/env" is ambiguous (could be <project>/<environment> or <org>/default/<environment>); prefer <org>/<project>/<environment>.