Merge pull request #71 from runcommand/fill-total-row

Fix bottom of the table when there aren't any items displayed
This commit is contained in:
Daniel Bachhuber 2016-09-08 06:23:36 -07:00 committed by GitHub
commit 3a0b093984
2 changed files with 15 additions and 4 deletions

View file

@ -28,3 +28,12 @@ Feature: Basic profile usage
"""
Error: 'SAVEQUERIES' is defined as false, and must be true. Please check your wp-config.php
"""
Scenario: Profile a hook without any callbacks
Given a WP install
When I run `wp profile --hook=setup_theme --fields=callback,time`
Then STDOUT should be a table containing rows:
| callback | time |
| total | |
And STDERR should be empty

View file

@ -60,16 +60,15 @@ class Formatter {
$table->setHeaders( $fields );
$totals = array(
'total',
);
$totals = array_fill( 0, count( $fields ), null );
$totals[0] = 'total';
foreach ( $items as $item ) {
$values = array_values( \WP_CLI\Utils\pick_fields( $item, $fields ) );
foreach( $values as $i => $value ) {
if ( 0 === $i ) {
continue;
}
if ( ! isset( $totals[ $i ] ) ) {
if ( null === $totals[ $i ] ) {
if ( stripos( $fields[ $i ], '_ratio' ) ) {
$totals[ $i ] = array();
} else {
@ -90,6 +89,9 @@ class Formatter {
$table->addRow( $values );
}
foreach( $totals as $i => $value ) {
if ( null === $value ) {
continue;
}
if ( stripos( $fields[ $i ], '_time' ) || 'time' === $fields[ $i ] ) {
$totals[ $i ] = round( $value, 4 ) . 's';
}