Skip to content

Fix misleading prompt when pcurl add --name X hits a host already covered by another profile#1

Open
kroexov wants to merge 1 commit into
vmkteam:masterfrom
kroexov:fix-add-host-conflict-prompt
Open

Fix misleading prompt when pcurl add --name X hits a host already covered by another profile#1
kroexov wants to merge 1 commit into
vmkteam:masterfrom
kroexov:fix-add-host-conflict-prompt

Conversation

@kroexov
Copy link
Copy Markdown

@kroexov kroexov commented May 14, 2026

context: i do not have this profile, i wrote it to set alternative token with different name to same origin
image

Summary

pcurl add --name X <curl> for a host already covered by a differently-named profile shows:

Profile "X" already exists. Update?

…even when X does not exist. The confusing message comes from confirmExisting collapsing two distinct cases:

  1. A profile named X already exists.
  2. No profile named X, but another profile (say Y) already lists this host in MatchHosts.

In case 2 the code already creates a new profile X independent of Y (useful for multi-account setups on the same host) — only the prompt was wrong.

Changes

  • internal/pcurl/add.go — split confirmExisting so each case has its own prompt.
  • internal/pcurl/prompt.go — add ConfirmHostConflict(newName, existingName, host) (huh + text fallback, default No since this creates a duplicate-host profile).
  • internal/pcurl/add_test.goTestAdd_HostConflict_Confirm / TestAdd_HostConflict_Decline.

Name-collision flow (ConfirmUpdate) is unchanged.

Test plan

  • go test ./internal/pcurl/ — all green, including the new tests
  • Manual: pcurl add --name newname curl <url-of-existing-host> shows the new wording and respects Yes/No
  • Manual: pcurl add --name existing curl <existing-url> still shows the original "already exists. Update?" prompt

Before, `pcurl add --name X <curl>` for a host already covered by a
differently-named profile prompted "Profile \"X\" already exists.
Update?" — but X did not exist. The misleading message came from
collapsing two cases in `confirmExisting`:

  1. A profile named X already exists.
  2. No profile named X, but another profile already covers the host.

Case 2 still proceeds to create a new profile under X (resulting in
two profiles for the same host), which is intentional and useful for
multi-account setups — only the prompt was wrong.

Split the logic so each case has its own prompt:

  * Name collision → existing `ConfirmUpdate` (default Yes), updates X.
  * Host conflict  → new `ConfirmHostConflict` (default No), creates X
    as a separate profile and leaves the original untouched.

Adds `TestAdd_HostConflict_Confirm` / `TestAdd_HostConflict_Decline`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant