Skip to content

Add support for argument aliases#6176

Merged
swissspidy merged 26 commits into
mainfrom
copilot/add-argument-aliases-support
Mar 10, 2026
Merged

Add support for argument aliases#6176
swissspidy merged 26 commits into
mainfrom
copilot/add-argument-aliases-support

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Dec 20, 2025

  • Understand the existing codebase structure for argument handling
  • Implement new inline pipe-based alias syntax: [--with-dependencies|w], [--verbose|v|wordy|deprecated-name]
  • SynopsisParser: parse aliases from |-separated parts of parameter tokens
  • SynopsisParser: render aliases back into output
  • SynopsisParser: ignore | inside <> brackets (e.g., <plugin|zip>)
  • DocParser: removed old YAML-based get_arg_aliases() implementation
  • Subcommand: build alias map from parsed synopsis in invoke(); removed $original_docparser
  • Subcommand: fix conflict detection to use assoc/flag names only (not positional)
  • Subcommand: merge alias values for repeating parameters instead of discarding them
  • PHPStan types: added aliases?: string[] to Flag/Assoc/PositionalParameter
  • Feature tests: rewritten with pipe syntax, added help output test
  • Unit tests: rewritten for SynopsisParser-based API
  • All checks passing: phpunit, phpcs, phpstan
Original prompt

This section details on the original issue you should resolve

<issue_title>Add support for argument aliases</issue_title>
<issue_description>## Feature Request

Describe your use case and the problem you are facing

For most CLI tools it's common to have short and long form argument names that can be used interchangeably.

For example, npm install --save-dev is the same as npm install -D (or even npm i -D). composer update --with-dependencies is the same as composer update -w.

WP-CLI doesn't have that.

Describe the solution you'd like

Similar to command aliases, it would be nice to define aliases for arguments as well, both local and global. They could be used to define such shorter versions, but also for renaming deprecated arguments (like the deprecated --blog global argument).

An argument should be able to have multiple aliases.

If an --with-dependencies argument has an alias -w and I run wp <mycommand> -w, the $assoc_args array should still use the with-dependencies array key, so there should be no code change needed to accommodate the aliased version.


Related:

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits December 20, 2025 20:09
- Extended DocParser to parse 'alias' metadata from PHPdoc parameters
- Updated Subcommand to resolve aliases to canonical names before validation
- Modified Configurator to support single-dash short arguments (e.g., -w, -n=5)
- Added comprehensive unit tests for alias resolution
- Added Behat feature tests for argument aliases

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
- Store the original DocParser instance in Subcommand to access YAML metadata
- Fix access level visibility issue with $synopsis property
- Add debug logging for alias resolution
- Verify aliases work correctly with manual testing

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
@codecov
Copy link
Copy Markdown

codecov Bot commented Dec 20, 2025

Codecov Report

❌ Patch coverage is 84.17266% with 22 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
php/WP_CLI/Dispatcher/Subcommand.php 70.14% 20 Missing ⚠️
php/WP_CLI/Configurator.php 50.00% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

- Simplify alias resolution logic with two-pass approach
- Add documentation for single-letter short argument limitation
- Improve code clarity and maintainability

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copilot AI changed the title [WIP] Add support for argument aliases in WP-CLI Add support for argument aliases Dec 20, 2025
Copilot AI requested a review from swissspidy December 20, 2025 20:21
@swissspidy

This comment was marked as resolved.

YAML parsers interpret 'n', 'N', 'y', 'Y' as boolean values (false/true).
This caused single-letter aliases like 'n' to be parsed as false and then
converted to empty strings. Added special handling to convert boolean false
back to 'n' and boolean true to 'y', along with proper type conversion and
empty string filtering.

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>

This comment was marked as resolved.

@swissspidy swissspidy marked this pull request as ready for review December 20, 2025 21:51
@swissspidy swissspidy requested a review from a team as a code owner December 20, 2025 21:51
@github-actions github-actions Bot added command:cli Related to 'cli' command command:cli-alias Related to 'cli alias' command command:cli-cache Related to 'cli cache' command command:config labels Dec 22, 2025
@swissspidy swissspidy requested a review from Copilot January 21, 2026 18:58
@swissspidy

This comment was marked as resolved.

gemini-code-assist[bot]

This comment was marked as resolved.

This comment was marked as resolved.

@swissspidy

This comment was marked as resolved.

Replaces YAML-based alias metadata with a simpler inline pipe-separated
syntax in the parameter synopsis line:

  [--with-dependencies|w]
  [--verbose|v|wordy|deprecated-name]
  [--number=<number>|n]

Changes:
- SynopsisParser: Added extract_aliases() to parse pipe-separated aliases
  from tokens (| inside <> brackets is ignored), updated classify_token()
  to store aliases in $param['aliases'], updated render() to include aliases
- DocParser: Removed get_arg_aliases() (YAML-based, no longer needed) and
  get_param_or_flag_args() helper
- Subcommand: Removed $original_docparser, invoke() now builds alias map
  directly from parsed synopsis
- class-wp-cli.php: Added aliases?: string[] to PHPStan type definitions
- Feature tests: Rewritten with new pipe syntax, added help output test
- Unit tests: Rewritten for new SynopsisParser-based API

Aliases are visible in `wp help` output since the synopsis shows the full
pipe-separated parameter definition (e.g., [--verbose|v|wordy]).

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>

This comment was marked as resolved.

This comment was marked as resolved.

@swissspidy

This comment was marked as resolved.

gemini-code-assist[bot]

This comment was marked as resolved.

This comment was marked as resolved.

@swissspidy

This comment was marked as resolved.

Two improvements to the alias resolution in invoke()/resolve_arg_aliases():

1. Repeating parameter merging (resolve_arg_aliases):
   - Refactored to a two-pass approach: first copy all non-alias entries,
     then process aliases
   - For repeating assoc params (e.g. [--status=<status>...|s]), alias
     values are now merged with any already-present canonical values instead
     of being silently discarded (e.g. --status=a -s=b now gives ['a','b'])
   - invoke() builds a $repeating_params map from the synopsis and passes
     it through to resolve_arg_aliases()

2. Conflict detection scope (invoke):
   - Previously built the conflict set from get_parameters(), which
     includes positional parameter names; this incorrectly flagged aliases
     that matched a positional name as conflicts
   - Now builds $assoc_flag_names from assoc/flag params only (local +
     global), so positional parameter names no longer block alias
     registration

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>

This comment was marked as resolved.

@swissspidy swissspidy merged commit 84f29b9 into main Mar 10, 2026
69 checks passed
@swissspidy swissspidy deleted the copilot/add-argument-aliases-support branch March 10, 2026 13:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking-change command:cli Related to 'cli' command command:cli-alias Related to 'cli alias' command command:cli-cache Related to 'cli cache' command command:config scope:distribution Related to distribution

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for argument aliases

3 participants