diff --git a/cmd/esc/cli/cli_test.go b/cmd/esc/cli/cli_test.go index bcb65279..859aa82e 100644 --- a/cmd/esc/cli/cli_test.go +++ b/cmd/esc/cli/cli_test.go @@ -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( diff --git a/cmd/esc/cli/env.go b/cmd/esc/cli/env.go index cf67cee6..065ee0b4 100644 --- a/cmd/esc/cli/env.go +++ b/cmd/esc/cli/env.go @@ -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 / or /default/); prefer //.\n", + refString, + ) +} + func (cmd *envCommand) parseRef(refStr string) environmentRef { var orgName, projectName, envNameAndVersion string @@ -223,6 +231,10 @@ func (cmd *envCommand) getNewEnvRef( } } + if existsLegacyPath { + cmd.warnIfAmbiguousTwoPartRef(cmd.envNameFlag) + } + if !existsProject && existsLegacyPath { return legacyRef, args, nil } @@ -279,6 +291,10 @@ func (cmd *envCommand) getExistingEnvRefWithRelative( legacyRef.envName, ) + if existsLegacyPath { + cmd.warnIfAmbiguousTwoPartRef(refString) + } + // Require unambiguous path if both paths exist if exists && existsLegacyPath { return ref, ambiguousIdentifierError{ diff --git a/cmd/esc/cli/testdata/env-ambiguous-two-part-warning.yaml b/cmd/esc/cli/testdata/env-ambiguous-two-part-warning.yaml new file mode 100644 index 00000000..6719a996 --- /dev/null +++ b/cmd/esc/cli/testdata/env-ambiguous-two-part-warning.yaml @@ -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 / or /default/); prefer //.