Only display pagination when format=table

This commit is contained in:
Daniel Bachhuber 2017-10-12 15:46:29 -07:00
parent 5a1c7b0616
commit 5efaff7f16
2 changed files with 12 additions and 3 deletions

View file

@ -3,11 +3,17 @@ Feature: Search WordPress.org plugins
Scenario: Search for plugins with active_installs field
Given a WP install

When I run `wp plugin search foo --fields=name,slug,active_installs --format=csv`
When I run `wp plugin search foo --fields=name,slug,active_installs`
Then STDOUT should contain:
"""
Success: Showing
"""

When I run `wp plugin search foo --fields=name,slug,active_installs --format=csv`
Then STDOUT should not contain:
"""
Success: Showing
"""
And STDOUT should contain:
"""
name,slug,active_installs

View file

@ -584,6 +584,7 @@ abstract class CommandWithUpgrade extends \WP_CLI_Command {
$fields[ $field ] = true;
}

$format = ! empty( $assoc_args['format'] ) ? $assoc_args['format'] : 'table';
$formatter = $this->get_formatter( $assoc_args );

$api_args = array(
@ -609,8 +610,10 @@ abstract class CommandWithUpgrade extends \WP_CLI_Command {

$items = $api->$plural;

if ( 'table' === $format ) {
$count = \WP_CLI\Utils\get_flag_value( $api->info, 'results', 'unknown' );
\WP_CLI::success( sprintf( 'Showing %s of %s %s.', count( $items ), $count, $plural ) );
}

$formatter->display_items( $items );
}