Skip to content

Commit

Permalink
raise errors when ambiguous env id uses legacy format
Browse files Browse the repository at this point in the history
  • Loading branch information
dschaller committed Sep 6, 2024
1 parent 171f33d commit 5dab5cd
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions cmd/esc/cli/env_clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 <project-name>/<env-name>
if (err != nil && ref.isUsingLegacyID) || ref.isUsingLegacyID {
return errors.New("source environment ID must be at least <project-name>/<env-name>")
}

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
}
Expand Down

0 comments on commit 5dab5cd

Please sign in to comment.