Skip to content

Replace yargs-parser with commander for CLI option parsing#1192

Draft
Copilot wants to merge 7 commits intomainfrom
copilot/convert-commands-to-commander
Draft

Replace yargs-parser with commander for CLI option parsing#1192
Copilot wants to merge 7 commits intomainfrom
copilot/convert-commands-to-commander

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 28, 2026

  • Convert from yargs-parser to commander, ban unknown options, enhance error messages
  • Restructure to use .command() for all known commands (no default command)
  • Convert to commander help text with descriptions on all options/commands
  • Remove CliOptions.help and CliOptions.version (commander handles these natively)
  • Update cli.ts dispatch for config get/config list and CommanderError handling
  • Update configGet.ts to use configSettingName
  • Update all tests for subcommand structure
  • --config is now the primary option; --config-path is a hidden alias
  • TODO added for upgrading alias handling when commander supports Option.alias()
  • Docs updated to reflect --config as the primary option

Before and after behavior

Behavior Before (yargs-parser) After (commander)
Unknown options Silently ignored Rejected with error message
--help Custom showHelp() output Commander's built-in per-command help
--version Manual check in cli.ts Commander's built-in --version
Option format camelCase accepted (e.g. --gitTags) Requires dashed form (e.g. --git-tags) with helpful suggestions
Boolean negation --no-X (yargs implicit) Explicit --no-X options defined per flag
Config path option --config-path primary, --config hidden --config primary (-c), --config-path hidden alias
config command Positional args via _extraPositionalArgs Proper subcommands: config get <name>, config list
Option descriptions None (help was hand-written) Defined on each option, powers --help output
camelCase options Silently accepted Rejected with suggestion (e.g. --gitTagsDid you mean --git-tags or --no-git-tags?)

📍 Connect Copilot coding agent with Jira, Azure Boards or Linear to delegate work to Copilot in one click without leaving your project management tool.

Copilot AI added 2 commits March 28, 2026 03:02
- Replace yargs-parser with commander package (v10, Node 14+ compatible)
- Remove yargs-parser and @types/yargs-parser dependencies
- Ban unknown options (commander rejects unrecognized options)
- Remove --bool=false and --bool false support in favor of --no-bool
- Duplicate non-array options now use last-write-wins instead of throwing
- CamelCase input (--gitTags) no longer accepted; use hyphenated (--git-tags)
- Update tests to match new behavior
- All existing options, aliases, and commands preserved

Agent-Logs-Url: https://github.com/microsoft/beachball/sessions/b10c3147-797f-4524-a56d-1f2537833d47
Comment on lines +155 to +163
// Handle --config as alias for --config-path
if (commanderOpts.config !== undefined) {
if (commanderOpts.configPath !== undefined) {
throw new Error('Cannot specify both --config and --config-path');
}
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
commanderOpts.configPath = commanderOpts.config;
}
delete commanderOpts.config;
Copy link
Copy Markdown
Member

@ecraig12345 ecraig12345 Mar 28, 2026

Choose a reason for hiding this comment

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

@copilot Use commander's built-in alias support instead

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 Change it so --config is the primary option, and --config-path is an alias. You can handle it with new Option(...).alias('--config-path')

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Switched to --config as the primary option (with -c short form) and --config-path as a hidden alias. Commander v10 doesn't have .alias() on Option, so both are defined as separate options with --config-path hidden via .hideHelp(). The post-processing merges both into the configPath field on cliOptions. Done in 44c6910.

Copilot AI and others added 3 commits March 28, 2026 06:17
The CLI parser now requires a command name in argv. Updated all test
files that passed argv: [] to getParsedOptions to include the
appropriate command name (bump, change, check, or publish) based on
each test's context.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Use .command() for all known commands (change, check, bump, publish, canary, init, sync)
- Add config get <name> and config list as proper subcommands with positional arg
- Add option descriptions for commander-generated help text
- Remove default command (subcommand is now required)
- Replace _extraPositionalArgs with configSettingName
- Remove showHelp() in favor of commander's built-in help
- Remove CliOptions.help and CliOptions.version (commander handles these)
- Handle commander help/version errors in cli.ts catch block
- Use standard program.version() format
- Update all tests for new subcommand structure

Agent-Logs-Url: https://github.com/microsoft/beachball/sessions/637df71a-fa66-490b-98ee-ab96f3469c64
Copy link
Copy Markdown
Member

@ecraig12345 ecraig12345 left a comment

Choose a reason for hiding this comment

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

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