feat(auth): add --user option to oo auth switch#241
Conversation
Previously `oo auth switch` could only rotate to the next saved account, which made scripted workflows pick the right account by running the command multiple times. The new `-u, --user <user>` option resolves a target account by exact `account.id` first and then by exact unique `account.name`, exiting non-zero without rewriting `auth.toml` when the value is ambiguous or unmatched. Telemetry records a low-cardinality `has_user_filter` boolean so adoption of the new flag can be measured without capturing any account identity. Docs and the i18n catalog are updated in lock step with the user-facing contract. Signed-off-by: Kevin Cui <bh@bugs.cc>
Summary by CodeRabbit
WalkthroughThis PR extends the 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches✨ Simplify code
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/application/commands/auth/switch.ts (1)
17-17: ⚡ Quick winConsider narrowing the type to success-path values only.
The
SwitchMatchKindtype includes"ambiguous"and"not_found", but these values can never reach the success path (lines 52-60) becauseresolveAccountByUserthrows for both cases (lines 90, 95). This makes the type broader than necessary and could mislead future maintainers about which values can appear in logs or telemetry.♻️ Narrow the type to success values
-type SwitchMatchKind = "ambiguous" | "id" | "name" | "next" | "not_found"; +type SwitchMatchKind = "id" | "name" | "next";🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/application/commands/auth/switch.ts` at line 17, SwitchMatchKind is wider than needed because resolveAccountByUser throws on "ambiguous" and "not_found"; narrow the union to only the success-path variants ("id" | "name" | "next") by updating the type alias SwitchMatchKind and any related logging/telemetry that consumes it (e.g., usages inside switchAccount or resolveAccountByUser) so callers only expect the actual possible values on the success path.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/application/commands/auth/switch.ts`:
- Line 17: SwitchMatchKind is wider than needed because resolveAccountByUser
throws on "ambiguous" and "not_found"; narrow the union to only the success-path
variants ("id" | "name" | "next") by updating the type alias SwitchMatchKind and
any related logging/telemetry that consumes it (e.g., usages inside
switchAccount or resolveAccountByUser) so callers only expect the actual
possible values on the success path.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: ba539b7d-038b-4895-ab1c-2bc46429a51d
📒 Files selected for processing (6)
docs/commands.mddocs/commands.zh-CN.mdsrc/application/commands/auth/index.cli.test.tssrc/application/commands/auth/switch.tssrc/application/commands/telemetry-decisions.test.tssrc/i18n/catalog.ts
Previously
oo auth switchcould only rotate to the next saved account, which made scripted workflows pick the right account by running the command multiple times. The new-u, --user <user>option resolves a target account by exactaccount.idfirst and then by exact uniqueaccount.name, exiting non-zero without rewritingauth.tomlwhen the value is ambiguous or unmatched.Telemetry records a low-cardinality
has_user_filterboolean so adoption of the new flag can be measured without capturing any account identity. Docs and the i18n catalog are updated in lock step with the user-facing contract.