Skip to content

refactor: replace process.argv.includes() with centralized type-safe arg parsing#143

Merged
scottlovegrove merged 2 commits intomainfrom
scottl/args
Apr 5, 2026
Merged

refactor: replace process.argv.includes() with centralized type-safe arg parsing#143
scottlovegrove merged 2 commits intomainfrom
scottl/args

Conversation

@scottlovegrove
Copy link
Copy Markdown
Collaborator

Summary

  • Introduces src/lib/global-args.ts — a centralized module that parses well-known global CLI flags from process.argv once (lazily cached), correctly handling --flag=value variants and --progress-jsonl value extraction
  • Removes scattered process.argv.includes() checks from output.ts, spinner.ts, input.ts, public-channels.ts, and progress.ts
  • Updates all 15 consumer files to import isAccessible/isNonInteractive/includePrivateChannels/shouldDisableSpinner directly from global-args.ts

Test plan

  • New global-args.test.ts covers: long flags, flag defaults, --progress-jsonl value extraction (all forms), last-one-wins, shouldDisableSpinner(), isAccessible() env var interaction, isNonInteractive() TTY detection, includePrivateChannels() env var interaction, singleton caching + reset
  • Updated spinner.test.ts, progress.test.ts, output.test.ts, input.test.ts, public-channels.test.ts with resetGlobalArgs() in setup/teardown
  • Updated mocks in inbox.test.ts, search.test.ts, channel.test.ts to target global-args.js
  • All 387 existing tests pass
  • lint:check + type-check passes

🤖 Generated with Claude Code

…arg parsing

Introduces src/lib/global-args.ts — a centralized module that parses
well-known global CLI flags from process.argv once (lazily cached).
Removes scattered process.argv.includes() checks from output.ts,
spinner.ts, input.ts, public-channels.ts, and progress.ts. Updates all
consumer files to import directly from global-args.ts.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@scottlovegrove scottlovegrove self-assigned this Apr 5, 2026
@doistbot doistbot requested a review from pauloslund April 5, 2026 18:37
@scottlovegrove scottlovegrove added the 👀 Show PR PR must be reviewed before or after merging label Apr 5, 2026
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 nicely centralizes command-line argument parsing into a single, type-safe module while cleaning up scattered process.argv checks. It is a great refactoring that significantly improves the maintainability and testability of the CLI's global flag handling. There are just a couple of minor adjustments noted for the --progress-jsonl flag parsing to prevent false positive prefix matches and correctly handle output paths containing equals signs.

Share FeedbackReview Logs

Address review feedback:
- Use exact match + = prefix instead of startsWith to avoid false
  positives from hypothetical flags like --progress-jsonl-format
- Use slice(indexOf('=') + 1) instead of split('=', 2) to preserve
  paths containing = characters

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@scottlovegrove scottlovegrove merged commit 7d2ef79 into main Apr 5, 2026
4 checks passed
@scottlovegrove scottlovegrove deleted the scottl/args branch April 5, 2026 18:43
@doist-release-bot
Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 2.23.2 🎉

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

released 👀 Show PR PR must be reviewed before or after merging

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants