Skip to content

Switch to commander for arg parsing#1303

Merged
ecraig12345 merged 11 commits into
mainfrom
copilot/convert-beachball-to-commander-14
Jul 4, 2026
Merged

Switch to commander for arg parsing#1303
ecraig12345 merged 11 commits into
mainfrom
copilot/convert-beachball-to-commander-14

Conversation

Copilot AI commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Description

Replaces yargs-parser with commander@14 for CLI option parsing in getCliOptions.ts. Commander is currently used only for parsing, not for command dispatch — the existing cli.ts dispatch (switch on cliOptions.command) is unchanged. All options are declared on a single parent command (so they can appear before or after the command name), with config declared as a subcommand so its extra positional args (config get <name>) are handled natively.

Changes

  • src/options/getCliOptions.ts: rewritten to build a commander Command:
    • Each option declared in its canonical dashed form — string, numeric (with non-numeric validation), boolean (plus --no- negation), and array (variadic + collector) — along with short aliases and a [command] positional.
    • exitOverride() + silenced output make parsing throw rather than call process.exit() or write to stdout/stderr, so callers and tests handle failures.
    • A normalizeArgv preprocessing pass reproduces permissive yargs-parser behaviors 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).
    • Post-parse logic (branch resolution, canary tag handling, NPM_TOKEN, _extraPositionalArgs, project-root lookup) is preserved.
  • src/types/BeachballOptions.ts: removed a stale comment referencing the old yargs-parser positional-args workaround.
  • Dependencies: added commander@^14.0.3; removed yargs-parser and @types/yargs-parser (package.json, yarn.lock).
  • Tests (getCliOptions.test.ts): updated to reflect the two intentional breaking changes — unknown options now throw (unknown option '--foo'), and excess positional args throw commander's too many arguments.
  • Change file: added a major change file documenting the migration and breaking changes.

Breaking changes (v3)

  • Unknown options now error instead of being passed through (previously yargs-parser inferred their types and forwarded them).
  • -? is no longer accepted as an alias for --help (commander can't register ? as a short flag); use -h or --help.

Not included

Command dispatch still lives in cli.ts; migrating dispatch to commander subcommands is out of scope for this PR.

@ecraig12345 ecraig12345 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@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).

Comment thread packages/beachball/src/options/getCliOptions.ts
Comment thread packages/beachball/src/options/getCliOptions.ts Outdated
Comment thread packages/beachball/src/options/getCliOptions.ts Outdated
Copilot AI requested a review from ecraig12345 July 3, 2026 22:52
Copilot stopped work on behalf of ecraig12345 due to an error July 3, 2026 23:08
@ecraig12345 ecraig12345 changed the title Plan + first step: migrate CLI option parsing from yargs-parser to commander@14 Switch to commander for arg parsing Jul 3, 2026
@ecraig12345

Copy link
Copy Markdown
Member

@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.

Copilot AI commented Jul 3, 2026

Copy link
Copy Markdown
Contributor Author

@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 getC...

Added an optionDescriptions record in getCliOptions.ts with a short description for each option (sourced from help.ts and the BeachballOptions doc comments), and pass those to each commander Option. The record is keyed by every parseable option name, so adding a new option without a description is a compile error. Done in the latest commit.

@ecraig12345 ecraig12345 marked this pull request as ready for review July 3, 2026 23:32
@ecraig12345 ecraig12345 force-pushed the copilot/convert-beachball-to-commander-14 branch from ed4bd0b to 566d905 Compare July 4, 2026 01:17
@ecraig12345 ecraig12345 merged commit 7ba05ce into main Jul 4, 2026
11 checks passed
@ecraig12345 ecraig12345 deleted the copilot/convert-beachball-to-commander-14 branch July 4, 2026 01:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants