Skip to content

feat(auth): add attachLoginCommand Commander helper#13

Merged
scottlovegrove merged 2 commits into
mainfrom
scottl/auth-attach-login-command
May 9, 2026
Merged

feat(auth): add attachLoginCommand Commander helper#13
scottlovegrove merged 2 commits into
mainfrom
scottl/auth-attach-login-command

Conversation

@scottlovegrove
Copy link
Copy Markdown
Collaborator

Summary

  • Adds attachLoginCommand(parent, options): Command under @doist/cli-core/auth — a thin Commander helper that wires the standard flag set (--read-only, --callback-port, --json, --ndjson) and drives runOAuthFlow end-to-end so consumers don't hand-roll the wiring around the OAuth runtime.
  • Returns the new Command so consumers can chain .description(...) / .option(...) / .addHelpText(...). Consumer-attached options land in the flags object passed to resolveScopes and the downstream provider.
  • Inline parsePort rejects bad --callback-port values via CliError('AUTH_PORT_BIND_FAILED', ...).
  • Updates the README's auth row + "Auth (optional subpath)" usage block to match the actual 0.8.0 surface — drops references to registerAuthCommand / createConfigTokenStore / startCallbackServer that were trimmed before the 0.8.0 release.

Sibling helpers (attachLogoutCommand / attachStatusCommand / attachTokenCommand) deferred to a follow-up PR; their shape is clearer once a concrete consumer migration confirms the conventions.

Test plan

  • npm run check (oxlint + oxfmt)
  • npm run type-check
  • npm test — 217 passing (up from 207; +10 new tests in src/auth/login.test.ts)
  • Reviewer: skim README usage block against the actual src/auth/index.ts exports

New tests

src/auth/login.test.ts covers:

  • standard runOAuthFlow option assembly in human mode
  • --read-only threading into resolveScopes + runOAuthFlow
  • --callback-port override + CliError on non-integer / out-of-range values
  • --json / --ndjson suppress the authorize-URL fallback print
  • consumer-attached options land in flags while standard flags are stripped
  • custom openBrowser forwarded
  • returned Command is chainable

🤖 Generated with Claude Code

Wires `<cli> [auth] login` with the standard flag set (--read-only,
--callback-port, --json, --ndjson) and drives runOAuthFlow end-to-end,
so consumers don't hand-roll Commander wiring around the OAuth runtime.
Returns the new Command for chaining .description / .option /
.addHelpText; consumer-attached options land in the `flags` object
passed to resolveScopes and the downstream provider.

Updates the README's `auth` row + usage block to match the actual
0.8.0 surface (drops references to registerAuthCommand /
createConfigTokenStore / startCallbackServer that were trimmed before
the 0.8.0 release).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Member

@doistbot doistbot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR introduces the attachLoginCommand helper to streamline OAuth flow wiring for consumers and updates the related README documentation. It is a great addition that cleanly encapsulates the CLI flag setup and runtime orchestration, paving the way for easier consumer migrations. A few refinements are needed, specifically around preserving the authorization URL fallback in machine-output modes, exposing unstripped flags to the onSuccess hook, reusing the existing ViewOptions type, and tightening up both the port validation logic and test assertions.

Share FeedbackReview Logs

Comment thread src/auth/login.ts Outdated
Comment thread src/auth/login.ts Outdated
Comment thread src/auth/login.ts Outdated
Comment thread src/auth/login.ts Outdated
Comment thread src/auth/login.test.ts Outdated
Comment thread src/auth/login.test.ts Outdated
Comment thread src/auth/login.test.ts Outdated
- onAuthorizeUrl fallback (P1): under --json/--ndjson the helper now
  routes the authorize URL to stderr rather than swallowing it, so a
  missing/throwing `open` peer can no longer hang the flow until
  AUTH_CALLBACK_TIMEOUT. Consumers can pass `onAuthorizeUrl` to
  override.
- onSuccess receives `flags` (P2): switched to a single context object
  `{ account, view, flags }` so consumer-attached options stay reachable
  post-flow, not just inside resolveScopes.
- Reuse `Required<ViewOptions>` (P2): drops the duplicate AttachLoginView
  shape; renames the renamed export to AttachLoginContext.
- parsePort dedup (P2): single throw branch covering non-integer +
  out-of-range cases.
- Tests (P2): port-validation cases now match on `AUTH_PORT_BIND_FAILED`
  and assert runOAuthFlow was not called; the --json/--ndjson cases
  drive the supplied onAuthorizeUrl through the mock and assert stderr
  received the URL while console.log stayed untouched; provider/store
  stubs simplified to `{} as ...` and asserted forwarded.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@scottlovegrove scottlovegrove merged commit bb921b8 into main May 9, 2026
3 checks passed
@scottlovegrove scottlovegrove deleted the scottl/auth-attach-login-command branch May 9, 2026 18:37
doist-release-bot Bot added a commit that referenced this pull request May 9, 2026
## [0.9.0](v0.8.0...v0.9.0) (2026-05-09)

### Features

* **auth:** add attachLoginCommand Commander helper ([#13](#13)) ([bb921b8](bb921b8))
@doist-release-bot
Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 0.9.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants