@@ -596,6 +596,8 @@ public function size( $args, $assoc_args ) {
596596 $ rows = array ();
597597 $ fields = array ( 'Name ' , 'Size ' );
598598
599+ $ default_unit = ( empty ( $ size_format ) ) ? ' B ' : '' ;
600+
599601 if ( $ tables ) {
600602
601603 // Add all of the table sizes
@@ -612,7 +614,7 @@ public function size( $args, $assoc_args ) {
612614 // Add the table size to the list.
613615 $ rows [] = array (
614616 'Name ' => $ table_name ,
615- 'Size ' => strtoupper ( $ table_bytes ) . " " . ' B ' ,
617+ 'Size ' => strtoupper ( $ table_bytes ) . $ default_unit ,
616618 );
617619 }
618620 } else {
@@ -627,7 +629,7 @@ public function size( $args, $assoc_args ) {
627629 // Add the database size to the list.
628630 $ rows [] = array (
629631 'Name ' => DB_NAME ,
630- 'Size ' => strtoupper ( $ db_bytes ) . " " . ' B ' ,
632+ 'Size ' => strtoupper ( $ db_bytes ) . $ default_unit ,
631633 );
632634 }
633635
@@ -657,17 +659,21 @@ public function size( $args, $assoc_args ) {
657659 break ;
658660 }
659661
660- $ rows [ $ index ]['Size ' ] = $ row ['Size ' ] / $ divisor . " " . ucfirst ( $ size_format );
662+ $ rows [ $ index ]['Size ' ] = ceil ( $ row ['Size ' ] / $ divisor ) . " " . strtoupper ( $ size_format );
661663 }
662664 }
663665
664- // Display the rows.
665- $ args = array (
666- 'format ' => $ format ,
667- );
666+ if ( ! empty ( $ size_format ) && ! $ tables ) {
667+ WP_CLI ::Line ( filter_var ( $ rows [0 ]['Size ' ], FILTER_SANITIZE_NUMBER_INT ) );
668+ } else {
669+ // Display the rows.
670+ $ args = array (
671+ 'format ' => $ format ,
672+ );
668673
669- $ formatter = new \WP_CLI \Formatter ( $ args , $ fields );
670- $ formatter ->display_items ( $ rows );
674+ $ formatter = new \WP_CLI \Formatter ( $ args , $ fields );
675+ $ formatter ->display_items ( $ rows );
676+ }
671677 }
672678
673679 /**
0 commit comments