Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ISO size formats to db size #104

Merged
merged 3 commits into from
Jul 31, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 32 additions & 2 deletions features/db-size.feature
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,45 @@ Feature: Display database size

When I run `wp db size --size_format=mb`
Then STDOUT should be a number



Scenario: Display only database size in gigabytes for a WordPress install
Given a WP install

When I run `wp db size --size_format=gb`
Then STDOUT should be a number



Scenario: Display only database size in terabytes for a WordPress install
Given a WP install

When I run `wp db size --size_format=tb`
Then STDOUT should be a number


Scenario: Display only database size in Kibibytes for a WordPress install
Given a WP install

When I run `wp db size --size_format=KB`
Then STDOUT should be a number


Scenario: Display only database size in Mebibytes for a WordPress install
Given a WP install

When I run `wp db size --size_format=MB`
Then STDOUT should be a number


Scenario: Display only database size in Gibibytes for a WordPress install
Given a WP install

When I run `wp db size --size_format=GB`
Then STDOUT should be a number


Scenario: Display only database size in Tebibytes for a WordPress install
Given a WP install

When I run `wp db size --size_format=TB`
Then STDOUT should be a number
33 changes: 32 additions & 1 deletion src/DB_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,15 @@ public function tables( $args, $assoc_args ) {
* - mb (megabytes)
* - gb (gigabytes)
* - tb (terabytes)
* - B (ISO Byte setting, with no conversion)
* - KB (ISO Kilobyte setting, with 1 kB = 1,000 B)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Case is wrong in explanation. kB => KB

* - KiB (ISO Kibibyte setting, with 1 KiB = 1,024 B)
* - MB (ISO Megabyte setting, with 1 MB = 1,000 kB)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Case is wrong in explanation. kB => KB

* - MiB (ISO Mebibyte setting, with 1 MiB = 1,024 KiB)
* - GB (ISO Gigabyte setting, with 1 GB = 1,000 MB)
* - GiB (ISO Gibibyte setting, with 1 GiB = 1,024 MiB)
* - TB (ISO Terabyte setting, with 1 TB = 1,000 GB)
* - TiB (ISO Tebibyte setting, with 1 TiB = 1,024 GiB)
* ---
*
* [--tables]
Expand Down Expand Up @@ -800,29 +809,51 @@ public function size( $args, $assoc_args ) {

// Display the database size as a number.
switch( $size_format ) {
case 'TB':
$divisor = pow( 1000, 4 );
break;

case 'GB':
$divisor = pow( 1000, 3 );
break;

case 'MB':
$divisor = pow( 1000, 2 );
break;

case 'KB':
$divisor = 1000;
break;

case 'tb':
case 'TiB':
$divisor = TB_IN_BYTES;
break;

case 'gb':
case 'GiB':
$divisor = GB_IN_BYTES;
break;

case 'mb':
case 'MiB':
$divisor = MB_IN_BYTES;
break;

case 'kb':
case 'KiB':
$divisor = KB_IN_BYTES;
break;

case 'b':
case 'B':
default:
$divisor = 1;
break;
}
$size_format_display = preg_replace( '/IB$/u', 'iB', strtoupper( $size_format ) );

$rows[ $index ]['Size'] = ceil( $row['Size'] / $divisor ) . " " . strtoupper( $size_format );
$rows[ $index ]['Size'] = ceil( $row['Size'] / $divisor ) . " " . $size_format_display;
}
}

Expand Down