Switch to commander for arg parsing#1303
Conversation
ecraig12345
left a comment
There was a problem hiding this comment.
@copilot Address the feedback below. Also update the PR title and description to reflect the current state (it's not adequate to just use commit messages).
|
@copilot Add a short description for each option, based on either packages/beachball/src/help.ts or the docs in BeachballOptions. The descriptions should probably be stored in a record within the getCliOptions file. |
Added an |
ed4bd0b to
566d905
Compare
Description
Replaces
yargs-parserwithcommander@14for CLI option parsing ingetCliOptions.ts. Commander is currently used only for parsing, not for command dispatch — the existingcli.tsdispatch (switch oncliOptions.command) is unchanged. All options are declared on a single parent command (so they can appear before or after the command name), withconfigdeclared as a subcommand so its extra positional args (config get <name>) are handled natively.Changes
src/options/getCliOptions.ts: rewritten to build a commanderCommand:--no-negation), and array (variadic + collector) — along with short aliases and a[command]positional.exitOverride()+ silenced output make parsing throw rather than callprocess.exit()or write to stdout/stderr, so callers and tests handle failures.normalizeArgvpreprocessing pass reproduces permissiveyargs-parserbehaviors commander lacks: camelCase flags (--gitTags), extra long aliases (--config,--force,--since), and boolean values passed via=or as a separate token (--fetch=false,--yes false).NPM_TOKEN,_extraPositionalArgs, project-root lookup) is preserved.src/types/BeachballOptions.ts: removed a stale comment referencing the old yargs-parser positional-args workaround.commander@^14.0.3; removedyargs-parserand@types/yargs-parser(package.json,yarn.lock).getCliOptions.test.ts): updated to reflect the two intentional breaking changes — unknown options now throw (unknown option '--foo'), and excess positional args throw commander'stoo many arguments.majorchange file documenting the migration and breaking changes.Breaking changes (v3)
-?is no longer accepted as an alias for--help(commander can't register?as a short flag); use-hor--help.Not included
Command dispatch still lives in
cli.ts; migrating dispatch to commander subcommands is out of scope for this PR.