diff --git a/cmd/esc/cli/env_clone.go b/cmd/esc/cli/env_clone.go index c6252f0a..717271f8 100644 --- a/cmd/esc/cli/env_clone.go +++ b/cmd/esc/cli/env_clone.go @@ -37,17 +37,23 @@ func newEnvCloneCmd(env *envCommand) *cobra.Command { return err } - ref := env.parseRef(args[0]) - if ref.isUsingLegacyID { - return errors.New("invalid source environment ID") + ref, args, err := env.getExistingEnvRef(ctx, args) + // An error will arise if an environment reference is ambiguous and can't be + // resolved to a single environment. The ref for the non-legacy environment will + // also be returned in this case. + // If the original ref is using a legacy ID of just env name return an error + // Otherwise we will ignore any conflict errors and assume the user meant / + if (err != nil && ref.isUsingLegacyID) || ref.isUsingLegacyID { + return errors.New("source environment ID must be at least /") } + if ref.version != "" { return errors.New("the clone command does not accept versions") } var destProject string - destName := args[1] - if project, name, hasDelimiter := strings.Cut(args[1], "/"); hasDelimiter { + destName := args[0] + if project, name, hasDelimiter := strings.Cut(args[0], "/"); hasDelimiter { destProject = project destName = name }