Skip to content

Commit de28cbc

Browse files
Copilotswissspidy
andcommitted
feat: support multiple values for field filter options in plugin/theme list
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
1 parent 1f4bb6e commit de28cbc

5 files changed

Lines changed: 59 additions & 5 deletions

File tree

features/plugin.feature

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,30 @@ Feature: Manage WordPress plugins
407407
| akismet | active | akismet/akismet.php |
408408
| wordpress-importer | inactive | wordpress-importer/wordpress-importer.php |
409409

410+
When I run `wp plugin list --status=active --status=inactive --fields=name,status,file`
411+
Then STDOUT should be a table containing rows:
412+
| name | status | file |
413+
| akismet | active | akismet/akismet.php |
414+
| wordpress-importer | inactive | wordpress-importer/wordpress-importer.php |
415+
416+
Scenario: Filter plugin list by multiple names
417+
Given a WP install
418+
419+
When I run `wp plugin install wordpress-importer --ignore-requirements`
420+
Then STDOUT should not be empty
421+
422+
When I run `wp plugin list --name=akismet,wordpress-importer --fields=name,status`
423+
Then STDOUT should be a table containing rows:
424+
| name | status |
425+
| akismet | inactive |
426+
| wordpress-importer | inactive |
427+
428+
When I run `wp plugin list --name=akismet --name=wordpress-importer --fields=name,status`
429+
Then STDOUT should be a table containing rows:
430+
| name | status |
431+
| akismet | inactive |
432+
| wordpress-importer | inactive |
433+
410434
@require-wp-5.2
411435
Scenario: Flag `--skip-update-check` skips update check when running `wp plugin list`
412436
Given a WP install

features/theme.feature

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -807,3 +807,27 @@ Feature: Manage WordPress themes
807807
"""
808808
classic
809809
"""
810+
811+
Scenario: Filter theme list by multiple names
812+
Given a WP install
813+
And I run `wp theme delete --all --force`
814+
And I run `wp theme install twentyeleven --activate`
815+
And I run `wp theme install twentytwelve`
816+
817+
When I run `wp theme list --name=twentytwelve,twentyeleven --fields=name,status`
818+
Then STDOUT should be a table containing rows:
819+
| name | status |
820+
| twentyeleven | active |
821+
| twentytwelve | inactive |
822+
823+
When I run `wp theme list --name=twentytwelve --name=twentyeleven --fields=name,status`
824+
Then STDOUT should be a table containing rows:
825+
| name | status |
826+
| twentyeleven | active |
827+
| twentytwelve | inactive |
828+
829+
When I run `wp theme list --status=active --status=inactive --fields=name,status`
830+
Then STDOUT should be a table containing rows:
831+
| name | status |
832+
| twentyeleven | active |
833+
| twentytwelve | inactive |

src/Plugin_Command.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1872,7 +1872,7 @@ public function delete( $args, $assoc_args ) {
18721872
* - yaml
18731873
* ---
18741874
*
1875-
* [--status=<status>]
1875+
* [--status=<status>...]
18761876
* : Filter the output by plugin status.
18771877
* ---
18781878
* options:

src/Theme_Command.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1021,7 +1021,7 @@ public function delete( $args, $assoc_args ) {
10211021
* - yaml
10221022
* ---
10231023
*
1024-
* [--status=<status>]
1024+
* [--status=<status>...]
10251025
* : Filter the output by theme status.
10261026
* ---
10271027
* options:

src/WP_CLI/CommandWithUpgrade.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -926,10 +926,16 @@ function ( $value ) {
926926
continue;
927927
}
928928

929-
// This can be either a value to filter by or a comma-separated list of values.
930-
// Also, it is not forbidden for a value to contain a comma (in which case we can filter only by one).
931929
$field_filter = $assoc_args[ $field ];
932-
if (
930+
if ( is_array( $field_filter ) ) {
931+
// Multiple values passed by repeating the argument (e.g., --name=plugin1 --name=plugin2).
932+
/** @var string[] $field_filter */
933+
if ( ! in_array( $item[ $field ], $field_filter, true ) ) {
934+
unset( $all_items[ $key ] );
935+
}
936+
} elseif (
937+
// This can be either a value to filter by or a comma-separated list of values.
938+
// Also, it is not forbidden for a value to contain a comma (in which case we can filter only by one).
933939
$item[ $field ] !== $field_filter
934940
&& ! in_array( $item[ $field ], array_map( 'trim', explode( ',', $field_filter ) ), true )
935941
) {

0 commit comments

Comments
 (0)