Skip to content

Commit 896b270

Browse files
authored
Merge pull request #81 from lukecav/master
Include support for TB and GB size formats
2 parents fec01e2 + 5b32b06 commit 896b270

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

features/db-size.feature

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,15 @@ Feature: Display database size
4949

5050
When I run `wp db size --size_format=mb`
5151
Then STDOUT should be a number
52+
53+
Scenario: Display only database size in gigabytes for a WordPress install
54+
Given a WP install
55+
56+
When I run `wp db size --size_format=gb`
57+
Then STDOUT should be a number
58+
59+
Scenario: Display only database size in terabytes for a WordPress install
60+
Given a WP install
61+
62+
When I run `wp db size --size_format=tb`
63+
Then STDOUT should be a number

src/DB_Command.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,8 @@ public function tables( $args, $assoc_args ) {
590590
* - b (bytes)
591591
* - kb (kilobytes)
592592
* - mb (megabytes)
593+
* - gb (gigabytes)
594+
* - tb (terabytes)
593595
* ---
594596
*
595597
* [--tables]
@@ -722,9 +724,23 @@ public function size( $args, $assoc_args ) {
722724
if ( ! defined( 'MB_IN_BYTES' ) ) {
723725
define( 'MB_IN_BYTES', 1024 * KB_IN_BYTES );
724726
}
727+
if ( ! defined( 'GB_IN_BYTES' ) ) {
728+
define( 'GB_IN_BYTES', 1024 * MB_IN_BYTES );
729+
}
730+
if ( ! defined( 'TB_IN_BYTES' ) ) {
731+
define( 'TB_IN_BYTES', 1024 * GB_IN_BYTES );
732+
}
725733

726734
// Display the database size as a number.
727735
switch( $size_format ) {
736+
case 'tb':
737+
$divisor = TB_IN_BYTES;
738+
break;
739+
740+
case 'gb':
741+
$divisor = GB_IN_BYTES;
742+
break;
743+
728744
case 'mb':
729745
$divisor = MB_IN_BYTES;
730746
break;

0 commit comments

Comments
 (0)