mirror of
https://hk.gh-proxy.com/https://github.com/wp-cli/profile-command.git
synced 2025-08-21 06:39:02 +08:00
Don't include 'total' cell when the name column is omitted
This commit is contained in:
parent
1025c4b464
commit
bf65cfd6f2
1 changed files with 10 additions and 4 deletions
|
@ -8,6 +8,8 @@ class Formatter {
|
||||||
|
|
||||||
private $args;
|
private $args;
|
||||||
|
|
||||||
|
private $total_cell_index;
|
||||||
|
|
||||||
public function __construct( &$assoc_args, $fields = null, $prefix = false ) {
|
public function __construct( &$assoc_args, $fields = null, $prefix = false ) {
|
||||||
$format_args = array(
|
$format_args = array(
|
||||||
'format' => 'table',
|
'format' => 'table',
|
||||||
|
@ -25,6 +27,8 @@ class Formatter {
|
||||||
$format_args['fields'] = explode( ',', $format_args['fields'] );
|
$format_args['fields'] = explode( ',', $format_args['fields'] );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->total_cell_index = array_search( $fields[0], $format_args['fields'] );
|
||||||
|
|
||||||
$format_args['fields'] = array_map( 'trim', $format_args['fields'] );
|
$format_args['fields'] = array_map( 'trim', $format_args['fields'] );
|
||||||
|
|
||||||
$this->args = $format_args;
|
$this->args = $format_args;
|
||||||
|
@ -38,7 +42,7 @@ class Formatter {
|
||||||
*/
|
*/
|
||||||
public function display_items( $items ) {
|
public function display_items( $items ) {
|
||||||
if ( 'table' === $this->args['format'] && empty( $this->args['field'] ) ) {
|
if ( 'table' === $this->args['format'] && empty( $this->args['field'] ) ) {
|
||||||
self::show_table( $items, $this->args['fields'] );
|
$this->show_table( $items, $this->args['fields'] );
|
||||||
} else {
|
} else {
|
||||||
$this->formatter->display_items( $items );
|
$this->formatter->display_items( $items );
|
||||||
}
|
}
|
||||||
|
@ -50,7 +54,7 @@ class Formatter {
|
||||||
* @param array $items
|
* @param array $items
|
||||||
* @param array $fields
|
* @param array $fields
|
||||||
*/
|
*/
|
||||||
private static function show_table( $items, $fields ) {
|
private function show_table( $items, $fields ) {
|
||||||
$table = new \cli\Table();
|
$table = new \cli\Table();
|
||||||
|
|
||||||
$enabled = \cli\Colors::shouldColorize();
|
$enabled = \cli\Colors::shouldColorize();
|
||||||
|
@ -61,11 +65,13 @@ class Formatter {
|
||||||
$table->setHeaders( $fields );
|
$table->setHeaders( $fields );
|
||||||
|
|
||||||
$totals = array_fill( 0, count( $fields ), null );
|
$totals = array_fill( 0, count( $fields ), null );
|
||||||
$totals[0] = 'total';
|
if ( ! is_null( $this->total_cell_index ) ) {
|
||||||
|
$totals[ $this->total_cell_index ] = 'total';
|
||||||
|
}
|
||||||
foreach ( $items as $item ) {
|
foreach ( $items as $item ) {
|
||||||
$values = array_values( \WP_CLI\Utils\pick_fields( $item, $fields ) );
|
$values = array_values( \WP_CLI\Utils\pick_fields( $item, $fields ) );
|
||||||
foreach( $values as $i => $value ) {
|
foreach( $values as $i => $value ) {
|
||||||
if ( 0 === $i ) {
|
if ( ! is_null( $this->total_cell_index ) && $this->total_cell_index === $i ) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if ( null === $totals[ $i ] ) {
|
if ( null === $totals[ $i ] ) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue