feat(auth): add account list/use Commander attachers#45
Conversation
Adds attachAccountListCommand + attachAccountUseCommand under the /auth
subpath, giving consumers `account list` / `account use <ref>` for
multi-account management. They consume TokenStore.list() / setDefault(),
which were required since 0.12.0 but had no consumer inside cli-core.
Mirrors the existing attachStatusCommand / attachLogoutCommand patterns:
optional renderText/renderJson overrides with sensible defaults, json
envelope { accounts, default } with ndjson one-object-per-line streaming,
and the logout-style success envelope (ndjson silent) for `use`.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
doistbot
left a comment
There was a problem hiding this comment.
Adding the new account list and use commands provides a solid foundation for multi-account credential management. These additions effectively bridge the gap for consumers leveraging the existing TokenStore contract. A few adjustments are needed to polish the implementation, such as updating the README to document the new exports, ensuring the JSON payload contract is consistent and validated across commands, and replacing the buffered NDJSON path with true streaming. Additionally, reusing the existing emitView utility for output formatting and refining the test suite to cover custom overrides while trimming redundant cases will help ensure long-term maintainability.
- Document the new exports in README (What's in it + Account selection usage block) per the AGENTS.md README-maintenance rule. - account list --ndjson now streams one object per account instead of buffering a joined string, matching the documented streaming contract. - account use --json now emits the resolved default account.id (re-read from list() after setDefault) so it round-trips against account list --json; the human line still echoes the raw ref. - Adopt the shared emitView helper for the json/human branches. - Add an --ndjson + custom renderJson test; replace the redundant raw-ref test with one asserting the canonical-vs-requested distinction. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
@doistbot /review |
doistbot
left a comment
There was a problem hiding this comment.
This PR expands the auth module's CLI capabilities by introducing commands to list and switch between multiple accounts. These additions close an important gap in credential management while mirroring the thoughtful design patterns established by existing commands. A few adjustments are needed to align the machine-output precedence and styling with established repository rules, optimize store reads, validate JSON payloads, extract shared flag parsing logic, and streamline the test suite's async assertions and mocking approaches.
- Machine-output precedence: --json now wins over --ndjson in both
commands (gate the ndjson cases behind !view.json), matching emitView
/ status / logout.
- account use only re-reads store.list() under --json (where the
canonical id is needed); human / --ndjson succeed off the original ref
so a follow-up read error can't fail an already-successful setDefault.
- Validate each per-account renderJson payload before serializing so a
non-serializable result throws CliError('INVALID_TYPE') in both machine
modes instead of nulling under --json.
- Extract splitViewFlags(cmd) and reuse it in both actions.
- Tests: rely on buildStore's natural ACCOUNT_NOT_FOUND throw; rewrite
the onDefaultSet test with a deferred hook to actually prove the
success line precedes the awaited hook; add json-wins + guard +
no-reread coverage; drop a restating comment.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
## [0.22.0](v0.21.0...v0.22.0) (2026-05-23) ### Features * **auth:** add account list/use Commander attachers ([#45](#45)) ([190770c](190770c))
|
🎉 This PR is included in version 0.22.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Summary
attachAccountListCommand+attachAccountUseCommandunder the@doist/cli-core/authsubpath, giving consumersaccount list/account use <ref>for multi-account credential management.TokenStore.list()/setDefault()— required on the contract since 0.12.0 but with zero consumer inside cli-core until now (the smell the roadmap flagged).attachStatusCommand/attachLogoutCommandpatterns: optionalrenderText/renderJsonoverrides with sensible defaults, hand-rolled json/ndjson/human branching, generics +.jsextensions +type(notinterface).Behavior
account list—--jsonemits{ accounts: [{ account, isDefault, … }], default: <ref|null> }wheredefaultis the default entry'saccount.id;--ndjsonstreams one per-account object per line (no envelope); human prints<label ?? id> (id:<id>)with a(default)marker. Renderers optional (unlikestatus) so a CLI gets working output with zero config.account use <ref>— positional<ref>→store.setDefault(ref), then✓ Default account set to <ref>(human) /{ ok: true, default: <ref> }(--json) / silent (--ndjson, matchinglogout).ACCOUNT_NOT_FOUNDpropagates unchanged. OptionalonDefaultSetfollow-up hook.Design notes
listis true streaming (one object per account); per-account shape is identical to the jsonaccounts[]entries.defaultis derived fromaccount.id(the contract's stable index key); stores with non-id ref-matching can override viarenderJson. Documented in JSDoc.Test plan
npm run build(tsc)npm test— 465 pass, incl. 21 new cases insrc/auth/account.test.tsnpm run check(oxlint + oxfmt) on the changed source🤖 Generated with Claude Code