Add support for argument aliases#6176
Merged
Merged
Conversation
- 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 Report❌ Patch coverage is
📢 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
This comment was marked as resolved.
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.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
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.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
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.
This comment was marked as resolved.
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.
[--with-dependencies|w],[--verbose|v|wordy|deprecated-name]|-separated parts of parameter tokens|inside<>brackets (e.g.,<plugin|zip>)get_arg_aliases()implementationinvoke(); removed$original_docparseraliases?: string[]to Flag/Assoc/PositionalParameterOriginal prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.