diff --git a/features/db-check.feature b/features/db-check.feature index aa5ce47b..7c105c82 100644 --- a/features/db-check.feature +++ b/features/db-check.feature @@ -13,6 +13,25 @@ Feature: Check the database Success: Database checked. """ + Scenario: db check with --quiet flag should only show errors + Given a WP install + + When I run `wp db check --quiet` + Then STDOUT should be empty + + Scenario: db check can explicitly pass --silent to mysqlcheck + Given a WP install + + When I run `wp db check --silent` + Then STDOUT should not contain: + """ + wp_cli_test.wp_users + """ + And STDOUT should contain: + """ + Success: Database checked. + """ + Scenario: Run db check with MySQL defaults to check the database Given a WP install diff --git a/features/db.feature b/features/db.feature index dbfdb4b0..1f44a6c5 100644 --- a/features/db.feature +++ b/features/db.feature @@ -185,6 +185,51 @@ Feature: Perform database operations """ And STDOUT should not be empty + Scenario: db optimize with --quiet flag should only show errors + Given a WP install + + When I run `wp db optimize --quiet` + Then STDOUT should not contain: + """ + error + """ + + + Scenario: db optimize can explicitly pass --silent to mysqlcheck + Given a WP install + + When I run `wp db optimize --silent` + Then STDOUT should not contain: + """ + error + """ + And STDOUT should contain: + """ + Success: Database optimized. + """ + + Scenario: db repair with --quiet flag should only show errors + Given a WP install + + When I run `wp db repair --quiet` + Then STDOUT should not contain: + """ + error + """ + + Scenario: db repair can explicitly pass --silent to mysqlcheck + Given a WP install + + When I run `wp db repair --silent` + Then STDOUT should not contain: + """ + error + """ + And STDOUT should contain: + """ + Success: Database repaired. + """ + Scenario: DB Query Given a WP install @@ -334,7 +379,7 @@ Feature: Perform database operations """ Query succeeded. Rows affected: 1 """ - + When I run `wp db query "SELECT * FROM wp_users WHERE ID = 1"` Then STDOUT should not contain: """ diff --git a/src/DB_Command.php b/src/DB_Command.php index 06781cee..222b4f6d 100644 --- a/src/DB_Command.php +++ b/src/DB_Command.php @@ -259,6 +259,12 @@ public function check( $_, $assoc_args ) { WP_CLI::debug( "Running shell command: {$command}", 'db' ); $assoc_args['check'] = true; + + // Pass --silent to mysqlcheck when in quiet mode. + if ( WP_CLI::get_config( 'quiet' ) ) { + $assoc_args['silent'] = true; + } + self::run( Utils\esc_cmd( $command, DB_NAME ), $assoc_args @@ -307,6 +313,12 @@ public function optimize( $_, $assoc_args ) { WP_CLI::debug( "Running shell command: {$command}", 'db' ); $assoc_args['optimize'] = true; + + // Pass --silent to mysqlcheck when in quiet mode. + if ( WP_CLI::get_config( 'quiet' ) ) { + $assoc_args['silent'] = true; + } + self::run( Utils\esc_cmd( $command, DB_NAME ), $assoc_args @@ -355,6 +367,12 @@ public function repair( $_, $assoc_args ) { WP_CLI::debug( "Running shell command: {$command}", 'db' ); $assoc_args['repair'] = true; + + // Pass --silent to mysqlcheck when in quiet mode. + if ( WP_CLI::get_config( 'quiet' ) ) { + $assoc_args['silent'] = true; + } + self::run( Utils\esc_cmd( $command, DB_NAME ), $assoc_args