/**
* Search wordpress.org plugin repo
*
- * @param object $api data from WP plugin/theme API
- * @param array $fields Data fields to display in table.
- * @param string $data_type Plugin or Theme api endpoint
+ * @param object $api Data from WP plugin/theme API
+ * @param array $fields Data fields to display in table.
+ * @param array $assoc_args Data passed in from command.
+ * @param string $data_type Plugin or Theme api endpoint
*/
- public function _search( $api, $fields, $data_type = 'plugin' ) {
+ public function _search( $api, $fields, $assoc_args, $data_type = 'plugin' ) {
// Sanitize to 1 of 2 types
$data_type = 'plugin' === $data_type ? 'plugin' : 'theme';
$set = set_site_transient( 'wpcli-$data_type-search-data', $data, 60*60 );
- \WP_CLI\Utils\format_items( 'table', $data, array_merge( array( 'key' ), $fields ) );
+ $format = isset( $assoc_args['format'] ) ? $assoc_args['format'] : 'table';
+
+ \WP_CLI\Utils\format_items( $format, $data, array_merge( array( 'key' ), $fields ) );
}
* --per-page
* : Optional number of results to display. Defaults to 10.
*
+ * --format
+ * : Output list as table, CSV or JSON. Defaults to table.
+ *
* --fields
* : Ask for specific fields from the API. Defaults to name,slug,author_profile,rating. acceptable values:
*
*
* ## EXAMPLES
*
- * wp plugin search dsgnwrks --per-page=20
+ * wp plugin search dsgnwrks --per-page=20 --format=json
*
* wp plugin search dsgnwrks --fields=name,version,slug,rating,num_ratings
*
- * @synopsis <plugin> [--per-page=<per-page>] [--fields=<fields>]
+ * @synopsis <plugin> [--per-page=<per-page>] [--fields=<fields>] [--format=<format>]
*/
public function search( $args, $assoc_args = array() ) {
$term = $args[0];
'search' => $term,
) );
- parent::_search( $api, $fields, 'plugin' );
-
+ parent::_search( $api, $fields, $assoc_args, 'plugin' );
}
protected function status_single( $args ) {