New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add --filter to many commands #3718
Changes from 8 commits
5b35ff4
5dc6984
db64208
0502032
0da8fb5
5f7d975
1c5f908
6e3c273
40774ad
b5c0345
1bc647c
93283ad
25e92dc
0096318
6bf87e1
9dcf533
86d9967
9004ed9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
Output Filters | ||
============== | ||
|
||
A number of Drush commands that output tabular data support a `--filter` option that allows rows from the output to be selected with simple logic expressions. | ||
|
||
In its simplest form, the `--filter` option takes a simple string that indicates the value to filter by in the command's *default filter field*. For example, the `role:list` command's default filter field is `perms`; the output of the `role:list` command can be limited to only those roles that have a specified permission: | ||
``` | ||
$ drush role:list --filter='post comments' | ||
authenticated: | ||
label: 'Authenticated user' | ||
perms: | ||
- 'access comments' | ||
- 'access content' | ||
- 'access shortcuts' | ||
- 'access site-wide contact form' | ||
- 'access user contact forms' | ||
- 'post comments' | ||
- 'search content' | ||
- 'skip comment approval' | ||
- 'use text format basic_html' | ||
``` | ||
Note that not all commands have a default filter field. | ||
|
||
Other fields in the output may be searched by using a simple expression in the `--filter` term. For example, to list only the enabled extensions with the `pm:list` command, you could run: | ||
``` | ||
$ drush pm:list --filter='status=enabled' | ||
``` | ||
To search for fields that contain a string using the operator `*=`, or match a regular expression with the `~=` operator. For example, to find all views whose machine name contains the word "content": | ||
``` | ||
drush views:list --filter='machine-name*=content' | ||
``` | ||
To use a regular expression to find any core requirement notice whose title contains either "php" or "gd" | ||
``` | ||
drush core:requirements --filter='title~=#(php|gd)#i' | ||
``` | ||
Finally, filter expressions may also use logical-and (`&&`) or logical-or (`||`) operations to separate multiple terms. Parenthesis are not supported. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -112,6 +112,8 @@ public function entityUpdates($options = ['cache-clear' => true]) | |
* description: Description | ||
* type: Type | ||
* @default-fields module,update_id,type,description | ||
* @filter-output | ||
* @filter-default-field module | ||
weitzman marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think 'type' would be a better default field here. |
||
* @return \Consolidation\OutputFormatters\StructuredData\RowsOfFields | ||
*/ | ||
public function updatedbStatus($options = ['format'=> 'table', 'entity-updates' => true, 'post-updates' => true]) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,7 @@ | |
* @command {{ machine_name }}:token | ||
* @aliases token | ||
* | ||
* @filter-output | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should declare a default field instead There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How do we pick which field is the default field? Assume There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this case I would go with “name”. This is just an example method. It’s not dynamically adjusted or anything. |
||
* @return \Consolidation\OutputFormatters\StructuredData\RowsOfFields | ||
*/ | ||
public function token($options = ['format' => 'table']) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for writing this ... I have two thoughts. I don't know how to handle them though.