Skip to content

Commit 6a18ea0

Browse files
swissspidyclaude
andauthored
Document the list filters these commands implement themselves (#638)
Co-authored-by: Claude Opus 5 <noreply@anthropic.com> Co-authored-by: Claude <noreply@anthropic.com>
1 parent 41a409d commit 6a18ea0

4 files changed

Lines changed: 262 additions & 2 deletions

File tree

‎features/site.feature‎

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -936,3 +936,108 @@ Feature: Manage sites in a multisite installation
936936
"""
937937
1
938938
"""
939+
940+
Scenario: Filter the site list by columns of the sites table
941+
Given a WP multisite install
942+
943+
When I run `wp site create --slug=first --porcelain`
944+
Then STDOUT should be a number
945+
And save STDOUT as {FIRST_ID}
946+
947+
When I run `wp site create --slug=second --porcelain`
948+
Then STDOUT should be a number
949+
And save STDOUT as {SECOND_ID}
950+
951+
# Give the two new sites contrasting statuses, so each filter below has
952+
# something to discriminate on and cannot pass by matching every site.
953+
When I run `wp site archive {FIRST_ID}`
954+
Then STDOUT should contain:
955+
"""
956+
Success:
957+
"""
958+
959+
When I run `wp site private {SECOND_ID}`
960+
Then STDOUT should contain:
961+
"""
962+
Success:
963+
"""
964+
965+
When I run `wp site spam {SECOND_ID}`
966+
Then STDOUT should contain:
967+
"""
968+
Success:
969+
"""
970+
971+
When I run `wp site list --format=count`
972+
Then STDOUT should be:
973+
"""
974+
3
975+
"""
976+
977+
When I run `wp site list --archived=1 --field=blog_id`
978+
Then STDOUT should be:
979+
"""
980+
{FIRST_ID}
981+
"""
982+
983+
When I run `wp site list --archived=0 --format=count`
984+
Then STDOUT should be:
985+
"""
986+
2
987+
"""
988+
989+
When I run `wp site list --public=0 --field=blog_id`
990+
Then STDOUT should be:
991+
"""
992+
{SECOND_ID}
993+
"""
994+
995+
When I run `wp site list --public=1 --format=count`
996+
Then STDOUT should be:
997+
"""
998+
2
999+
"""
1000+
1001+
When I run `wp site list --spam=1 --field=blog_id`
1002+
Then STDOUT should be:
1003+
"""
1004+
{SECOND_ID}
1005+
"""
1006+
1007+
When I run `wp site list --spam=0 --format=count`
1008+
Then STDOUT should be:
1009+
"""
1010+
2
1011+
"""
1012+
1013+
When I run `wp site list --deleted=0 --format=count`
1014+
Then STDOUT should be:
1015+
"""
1016+
3
1017+
"""
1018+
1019+
When I run `wp site list --blog_id={FIRST_ID} --field=blog_id`
1020+
Then STDOUT should be:
1021+
"""
1022+
{FIRST_ID}
1023+
"""
1024+
1025+
# site_id is the ID of the network the site belongs to, not the site's own ID.
1026+
When I run `wp site list --site_id=1 --format=count`
1027+
Then STDOUT should be:
1028+
"""
1029+
3
1030+
"""
1031+
1032+
When I run `wp site list --site_id=2 --format=count`
1033+
Then STDOUT should be:
1034+
"""
1035+
0
1036+
"""
1037+
1038+
# --network is an alias for site_id and takes precedence over it.
1039+
When I run `wp site list --site_id=2 --network=1 --format=count`
1040+
Then STDOUT should be:
1041+
"""
1042+
3
1043+
"""

‎features/user-application-password.feature‎

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,3 +315,93 @@ Feature: Manage user custom fields
315315
"""
316316
true
317317
"""
318+
319+
@require-wp-5.6
320+
Scenario: Filter application passwords by field
321+
Given a WP install
322+
323+
When I run `wp user application-password create 1 myapp --app-id=abc123 --porcelain`
324+
Then STDOUT should not be empty
325+
326+
When I run `wp user application-password create 1 otherapp --porcelain`
327+
Then STDOUT should not be empty
328+
329+
When I run `wp user application-password list 1 --format=count`
330+
Then STDOUT should be:
331+
"""
332+
2
333+
"""
334+
335+
When I run `wp user application-password list 1 --app_id=abc123 --field=name`
336+
Then STDOUT should be:
337+
"""
338+
myapp
339+
"""
340+
341+
When I run `wp user application-password list 1 --app-id=abc123 --field=name`
342+
Then STDOUT should be:
343+
"""
344+
myapp
345+
"""
346+
347+
When I run `wp user application-password list 1 --name=otherapp --field=name`
348+
Then STDOUT should be:
349+
"""
350+
otherapp
351+
"""
352+
353+
When I run `wp user application-password list 1 --name=myapp --field=uuid`
354+
Then STDOUT should not be empty
355+
And save STDOUT as {UUID}
356+
357+
When I run `wp user application-password list 1 --uuid={UUID} --field=name`
358+
Then STDOUT should be:
359+
"""
360+
myapp
361+
"""
362+
363+
When I run `wp user application-password list 1 --app_id=nosuchapp --format=count`
364+
Then STDOUT should be:
365+
"""
366+
0
367+
"""
368+
369+
# 'created' and 'last_used' are integers in core but strings on the command
370+
# line, so these only match if the comparison normalizes them.
371+
When I run `wp user application-password list 1 --name=myapp --field=created`
372+
Then STDOUT should not be empty
373+
And save STDOUT as {CREATED}
374+
375+
When I run `wp user application-password list 1 --created={CREATED} --field=name`
376+
Then STDOUT should contain:
377+
"""
378+
myapp
379+
"""
380+
381+
When I run `wp user application-password list 1 --created=1 --format=count`
382+
Then STDOUT should be:
383+
"""
384+
0
385+
"""
386+
387+
When I run `wp user application-password record-usage 1 {UUID}`
388+
Then STDOUT should contain:
389+
"""
390+
Success:
391+
"""
392+
393+
When I run `wp user application-password list 1 --name=myapp --field=last_used`
394+
Then STDOUT should not be empty
395+
And save STDOUT as {LAST_USED}
396+
397+
When I run `wp user application-password list 1 --last_used={LAST_USED} --field=name`
398+
Then STDOUT should be:
399+
"""
400+
myapp
401+
"""
402+
403+
When I run `wp user application-password list 1 --last-used={LAST_USED} --field=name`
404+
Then STDOUT should be:
405+
"""
406+
myapp
407+
"""

‎src/Site_Command.php‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,6 +1001,40 @@ private function get_network( $network_id ) {
10011001
* [--site-path=<path>]
10021002
* : Filter by path. Avoids conflict with the global `--path` parameter.
10031003
*
1004+
* [--blog_id=<blog_id>]
1005+
* : Filter by site ID.
1006+
*
1007+
* [--site_id=<site_id>]
1008+
* : Filter by the ID of the network the site belongs to. `--network` is an
1009+
* alias for this, and takes precedence when both are given.
1010+
*
1011+
* [--domain=<domain>]
1012+
* : Filter by domain.
1013+
*
1014+
* [--registered=<yyyy-mm-dd-hh-ii-ss>]
1015+
* : Filter by the date the site was registered.
1016+
*
1017+
* [--last_updated=<yyyy-mm-dd-hh-ii-ss>]
1018+
* : Filter by the date the site was last updated.
1019+
*
1020+
* [--public=<public>]
1021+
* : Filter by whether the site is public. Accepts 1 or 0.
1022+
*
1023+
* [--archived=<archived>]
1024+
* : Filter by whether the site is archived. Accepts 1 or 0.
1025+
*
1026+
* [--mature=<mature>]
1027+
* : Filter by whether the site is flagged as mature. Accepts 1 or 0.
1028+
*
1029+
* [--spam=<spam>]
1030+
* : Filter by whether the site is flagged as spam. Accepts 1 or 0.
1031+
*
1032+
* [--deleted=<deleted>]
1033+
* : Filter by whether the site is flagged as deleted. Accepts 1 or 0.
1034+
*
1035+
* [--lang_id=<lang_id>]
1036+
* : Filter by language ID.
1037+
*
10041038
* [--field=<field>]
10051039
* : Prints the value of a single field for each site.
10061040
*

‎src/User_Application_Password_Command.php‎

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,29 @@ final class User_Application_Password_Command {
8181
* [--<field>=<value>]
8282
* : Filter the list by a specific field.
8383
*
84+
* [--uuid=<uuid>]
85+
* : Filter by the universally unique ID of the application password.
86+
*
87+
* [--app_id=<app_id>]
88+
* : Filter by the application ID. `--app-id` is also accepted.
89+
*
90+
* [--name=<name>]
91+
* : Filter by the name of the application password.
92+
*
93+
* [--password=<password>]
94+
* : Filter by the hashed password.
95+
*
96+
* [--created=<created>]
97+
* : Filter by the Unix timestamp the application password was created at.
98+
*
99+
* [--last_used=<last_used>]
100+
* : Filter by the Unix timestamp the application password was last used at.
101+
* `--last-used` is also accepted.
102+
*
103+
* [--last_ip=<last_ip>]
104+
* : Filter by the IP address the application password was last used from.
105+
* `--last-ip` is also accepted.
106+
*
84107
* [--field=<field>]
85108
* : Prints the value of a single field for each application password.
86109
*
@@ -186,10 +209,18 @@ static function ( $a, $b ) use ( $orderby, $order ) {
186209

187210
$value = Utils\get_flag_value( $assoc_args, $field );
188211

212+
// 'created' and 'last_used' come back from core as integers, while an
213+
// argument always arrives as a string, so compare them as strings.
214+
$filter_value = is_scalar( $value ) ? (string) $value : '';
215+
189216
$application_passwords = array_filter(
190217
$application_passwords,
191-
static function ( $application_password ) use ( $field, $value ) {
192-
return $application_password[ $field ] === $value;
218+
static function ( $application_password ) use ( $field, $filter_value ) {
219+
$item_value = isset( $application_password[ $field ] ) && is_scalar( $application_password[ $field ] )
220+
? (string) $application_password[ $field ]
221+
: '';
222+
223+
return $item_value === $filter_value;
193224
}
194225
);
195226
}

0 commit comments

Comments
 (0)