Skip to content

Commit 608cfa5

Browse files
authored
Merge pull request #134 from thrijith/feature/GH-129
Fix `--all-tables` and `--all-tables-with-prefix` output when combined `--size_format`
2 parents c01088a + eec838b commit 608cfa5

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

features/db-size.feature

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,3 +152,28 @@ Feature: Display database size
152152
"""
153153

154154
But STDOUT should not be a number
155+
156+
Scenario: Display all table sizes for a WordPress install
157+
Given a WP install
158+
159+
When I run `wp db size --all-tables --size_format=kb`
160+
Then STDOUT should contain:
161+
"""
162+
wp_posts
163+
"""
164+
165+
And STDOUT should contain:
166+
"""
167+
KB
168+
"""
169+
170+
When I run `wp db size --all-tables-with-prefix --size_format=kb`
171+
Then STDOUT should contain:
172+
"""
173+
wp_posts
174+
"""
175+
176+
And STDOUT should contain:
177+
"""
178+
KB
179+
"""

src/DB_Command.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,8 @@ public function size( $args, $assoc_args ) {
772772
$human_readable = WP_CLI\Utils\get_flag_value( $assoc_args, 'human-readable', false );
773773
$tables = WP_CLI\Utils\get_flag_value( $assoc_args, 'tables' );
774774
$tables = ! empty( $tables );
775+
$all_tables = WP_CLI\Utils\get_flag_value( $assoc_args, 'all-tables' );
776+
$all_tables_with_prefix = WP_CLI\Utils\get_flag_value( $assoc_args, 'all-tables-with-prefix' );
775777

776778
if( ! is_null( $size_format ) && $human_readable ) {
777779
WP_CLI::error( "Cannot use --size_format and --human-readable arguments at the same time." );
@@ -792,7 +794,7 @@ public function size( $args, $assoc_args ) {
792794

793795
$default_unit = ( empty( $size_format ) && ! $human_readable ) ? ' B' : '';
794796

795-
if ( $tables ) {
797+
if ( $tables || $all_tables || $all_tables_with_prefix ) {
796798

797799
// Add all of the table sizes
798800
foreach( WP_CLI\Utils\wp_get_table_names( $args, $assoc_args ) as $table_name ) {
@@ -900,7 +902,7 @@ public function size( $args, $assoc_args ) {
900902
}
901903
}
902904

903-
if ( ! empty( $size_format) && ! $tables && ! $format && ! $human_readable ) {
905+
if ( ! empty( $size_format) && ! $tables && ! $format && ! $human_readable && true !== $all_tables && true !== $all_tables_with_prefix ) {
904906
WP_CLI::Line( filter_var( $rows[0]['Size'], FILTER_SANITIZE_NUMBER_INT ) );
905907
} else {
906908
// Display the rows.

0 commit comments

Comments
 (0)