refactor: replace process.argv.includes() with centralized type-safe arg parsing#143
Merged
scottlovegrove merged 2 commits intomainfrom Apr 5, 2026
Merged
refactor: replace process.argv.includes() with centralized type-safe arg parsing#143scottlovegrove merged 2 commits intomainfrom
scottlovegrove merged 2 commits intomainfrom
Conversation
…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>
doistbot
reviewed
Apr 5, 2026
Member
doistbot
left a comment
There was a problem hiding this comment.
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.
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>
Contributor
|
🎉 This PR is included in version 2.23.2 🎉 The release is available on: Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
src/lib/global-args.ts— a centralized module that parses well-known global CLI flags fromprocess.argvonce (lazily cached), correctly handling--flag=valuevariants and--progress-jsonlvalue extractionprocess.argv.includes()checks fromoutput.ts,spinner.ts,input.ts,public-channels.ts, andprogress.tsisAccessible/isNonInteractive/includePrivateChannels/shouldDisableSpinnerdirectly fromglobal-args.tsTest plan
global-args.test.tscovers: long flags, flag defaults,--progress-jsonlvalue extraction (all forms), last-one-wins,shouldDisableSpinner(),isAccessible()env var interaction,isNonInteractive()TTY detection,includePrivateChannels()env var interaction, singleton caching + resetspinner.test.ts,progress.test.ts,output.test.ts,input.test.ts,public-channels.test.tswithresetGlobalArgs()in setup/teardowninbox.test.ts,search.test.ts,channel.test.tsto targetglobal-args.jslint:check+type-checkpasses🤖 Generated with Claude Code