Skip to content

Add support for multiple flag values via repeated flags using ellipsis syntax - #6198

Merged
swissspidy merged 19 commits into
mainfrom
copilot/add-multiple-status-support
Mar 6, 2026
Merged

swissspidy merged 19 commits into
mainfrom
copilot/add-multiple-status-support

Conversation

Copilot AI commented Jan 19, 2026 •

Copy link
Copy Markdown
Contributor

Implementation Complete: Multiple Flag Values Support ✅

This PR implements support for passing the same flag multiple times to provide multiple values, addressing wp-cli/extension-command#159. Users can now use --status=active --status=parent instead of being limited to comma-separated values.

Core Changes

  • ✅ Modified Configurator::unmix_assoc_args() to collect multiple flag values into arrays
  • ✅ Updated Subcommand::validate_args() to handle repeating parameters using ellipsis syntax
  • ✅ Added validation for array values with improved error messages
  • ✅ Full backward compatibility maintained
  • ✅ Applied code review feedback: modern array destructuring, avoided end() side effects
  • ✅ Uses existing ellipsis syntax (...) consistent with repeating positional parameters
  • ✅ Consistent test output messages
  • ✅ Boolean flags use last-wins behavior (not aggregated into arrays)

Testing & Quality

  • ✅ Unit tests (8/8 pass in ConfiguratorTest)
  • ✅ Feature tests (4 scenarios, 36 steps, all pass)
  • ✅ Added test for invalid value appearing first in array
  • ✅ Added tests for boolean flag last-wins behavior
  • ✅ Linting, phpcs pass
  • ✅ CodeQL security scan (no issues)

Usage Example

# NEW: Use repeated flags
wp theme list --status=active --status=parent

# STILL WORKS: Comma-separated
wp theme list --status=active,parent

# STILL WORKS: Single value  
wp theme list --status=active

# Boolean flags use last-wins
wp command --verbose --no-verbose  # Results in --no-verbose (false)

How to Add to Your Command

Use the ellipsis syntax in the synopsis (same as for repeating positional parameters):

/**
 * [--status=<status>...]
 * : Filter by status
 * ---
 * options:
 *   - active
 *   - inactive
 * ---
 */

This leverages the existing $spec['repeating'] attribute from SynopsisParser, which already detects the ellipsis and works with infrastructure like prompt_args().

Important Notes

  • Boolean flags (--flag or --no-flag) use last-wins behavior - they are NOT aggregated into arrays
  • Value flags (--param=value) ARE aggregated into arrays when marked with ellipsis syntax
  • This prevents breaking downstream code that expects scalar boolean values

Follow-up Required

The changes in vendor files (Theme_Command.php, Plugin_Command.php, CommandWithUpgrade.php) need to be submitted to the wp-cli/extension-command repository separately. See MULTIPLE_FLAG_VALUES_IMPLEMENTATION.md for details.

Files Changed

  • php/WP_CLI/Configurator.php - Argument parsing with boolean flag handling
  • php/WP_CLI/Dispatcher/Subcommand.php - Validation logic using $spec['repeating']
  • tests/ConfiguratorTest.php - Unit tests including boolean flag tests
  • features/multiple-flag-values.feature - Feature tests with boolean flag scenario
  • MULTIPLE_FLAG_VALUES_IMPLEMENTATION.md - Documentation
Original prompt

This section details on the original issue you should resolve

<issue_title>wp theme list show multiple status</issue_title>
<issue_description>I am creating an audit script and noticed that you cannot use more than one status with the wp theme list command.

Here is an example on a live site:

wp theme list

Output

+----------------+--------+--------+---------+
| name           | status | update | version |
+----------------+--------+--------+---------+
| woodmart-child | active | none   | 1.0.0   |
| woodmart       | parent | none   | 4.4.0   |
+----------------+--------+--------+---------+

I can filter by one status

wp theme list --status=active

Output

+----------------+--------+--------+---------+
| name           | status | update | version |
+----------------+--------+--------+---------+
| woodmart-child | active | none   | 1.0.0   |
+----------------+--------+--------+---------+

But if I try to get both the active and parent status in one command it fails

wp theme list --status=active,parent

Output

+------+--------+--------+---------+
| name | status | update | version |
+------+--------+--------+---------+
+------+--------+--------+---------+

</issue_description>

<agent_instructions>Similar to the senstive: true annotation, there could be one called multiple: true. Then, when parsing arguments, if doing something like --flag=foo --flag=bar, if multiple: true is set, $assoc_args['flag'] would be an array [ 'foo', 'bar' ]</agent_instructions>

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

@swissspidy Sounds like it might be looking for a status called `active,parent` and not actually doing any splitting to filter by both.

So this would be more of an enhancement. I'd be open to accept a PR that covers all relevant commands and also clearly documents the behavior. Would also be good to check other commands as well to ensure they all behave similarly.</comment_new>
<comment_new>@thelovekesh
@swissspidy IMO It's hard to guess whether the user wants to pass comma-separated strings as multiple strings or the string itself contains the comma. In this case, we can explore the strategy to pass a flag multiple times in case multiple values are intended for a flag.

Example:

$ wp --flag=option1 --flag=option2
# It will be parsed by CLI as `$flag = [ 'option1', 'option2' ]`

$ wp --flag=option1,option2
# It will be parsed by CLI as `$flag = [ 'option1,option2' ]`
```</body></comment_new>
<comment_new><author>@danielbachhuber</author><body>
Related https://github.com/wp-cli/extension-command/issues/159</body></comment_new>
</comments>

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits January 19, 2026 10:25
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copilot AI and others added 3 commits January 19, 2026 10:29
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copilot AI changed the title [WIP] Add support for multiple statuses in wp theme list command Add support for multiple flag values via repeated flags Jan 19, 2026
Copilot AI requested a review from swissspidy January 19, 2026 10:33
@codecov

codecov Bot commented Jan 19, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 67.85714% with 9 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
php/WP_CLI/Configurator.php 43.75% 9 Missing ⚠️

📢 Thoughts on this report? Let us know!

This comment was marked as resolved.

…end()

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
@swissspidy
swissspidy marked this pull request as ready for review January 19, 2026 17:08
@swissspidy
swissspidy requested a review from a team as a code owner January 19, 2026 17:08
@swissspidy swissspidy added this to the 3.0.0 milestone Feb 5, 2026
@swissspidy

This comment was marked as resolved.

@swissspidy

This comment was marked as resolved.

gemini-code-assist[bot]

This comment was marked as resolved.

@swissspidy

This comment was marked as resolved.

Use "Filters: " consistently for both array and single value cases
to improve test output readability and clarity.

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>
Boolean flags (--flag or --no-flag) now use last-wins behavior when
repeated, preventing issues with downstream code that expects scalar
boolean values. Only non-boolean flags (--param=value) are aggregated
into arrays when repeated.

Added comprehensive tests:
- Unit test for boolean flag last-wins behavior
- Feature test scenario with multiple boolean flag combinations

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
@swissspidy
swissspidy merged commit 9f07e28 into main Mar 6, 2026
68 checks passed
@swissspidy
swissspidy deleted the copilot/add-multiple-status-support branch March 6, 2026 22:04
Copilot AI added a commit to wp-cli/media-command that referenced this pull request Mar 10, 2026
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants