Skip to content

Commit 0814b9c

Browse files
Copilotswissspidy
andcommitted
Add --quiet support for db check, optimize, and repair commands
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
1 parent 237d08f commit 0814b9c

File tree

2 files changed

+127
-0
lines changed

2 files changed

+127
-0
lines changed

features/db-quiet.feature

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
Feature: Quiet mode for database operations
2+
3+
Scenario: db check with --quiet flag should only show errors
4+
Given a WP install
5+
6+
When I run `wp db check --quiet`
7+
Then STDOUT should not contain:
8+
"""
9+
wp_cli_test.wp_users
10+
"""
11+
And STDOUT should be empty
12+
13+
Scenario: db optimize with --quiet flag should only show errors
14+
Given a WP install
15+
16+
When I run `wp db optimize --quiet`
17+
Then STDOUT should not contain:
18+
"""
19+
wp_cli_test.wp_users
20+
"""
21+
And STDOUT should be empty
22+
23+
Scenario: db repair with --quiet flag should only show errors
24+
Given a WP install
25+
26+
When I run `wp db repair --quiet`
27+
Then STDOUT should not contain:
28+
"""
29+
wp_cli_test.wp_users
30+
"""
31+
And STDOUT should be empty
32+
33+
Scenario: db check without --quiet flag should show informational messages
34+
Given a WP install
35+
36+
When I run `wp db check`
37+
Then STDOUT should contain:
38+
"""
39+
wp_cli_test.wp_users
40+
"""
41+
And STDOUT should contain:
42+
"""
43+
Success: Database checked.
44+
"""
45+
46+
Scenario: db optimize without --quiet flag should show informational messages
47+
Given a WP install
48+
49+
When I run `wp db optimize`
50+
Then STDOUT should contain:
51+
"""
52+
wp_cli_test.wp_users
53+
"""
54+
And STDOUT should contain:
55+
"""
56+
Success: Database optimized.
57+
"""
58+
59+
Scenario: db repair without --quiet flag should show informational messages
60+
Given a WP install
61+
62+
When I run `wp db repair`
63+
Then STDOUT should contain:
64+
"""
65+
wp_cli_test.wp_users
66+
"""
67+
And STDOUT should contain:
68+
"""
69+
Success: Database repaired.
70+
"""
71+
72+
Scenario: db check can explicitly pass --silent to mysqlcheck
73+
Given a WP install
74+
75+
When I run `wp db check --silent`
76+
Then STDOUT should not contain:
77+
"""
78+
wp_cli_test.wp_users
79+
"""
80+
And STDOUT should contain:
81+
"""
82+
Success: Database checked.
83+
"""
84+
85+
Scenario: db optimize can explicitly pass --silent to mysqlcheck
86+
Given a WP install
87+
88+
When I run `wp db optimize --silent`
89+
Then STDOUT should not contain:
90+
"""
91+
wp_cli_test.wp_users
92+
"""
93+
And STDOUT should contain:
94+
"""
95+
Success: Database optimized.
96+
"""
97+
98+
Scenario: db repair can explicitly pass --silent to mysqlcheck
99+
Given a WP install
100+
101+
When I run `wp db repair --silent`
102+
Then STDOUT should not contain:
103+
"""
104+
wp_cli_test.wp_users
105+
"""
106+
And STDOUT should contain:
107+
"""
108+
Success: Database repaired.
109+
"""

src/DB_Command.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,12 @@ public function check( $_, $assoc_args ) {
259259
WP_CLI::debug( "Running shell command: {$command}", 'db' );
260260

261261
$assoc_args['check'] = true;
262+
263+
// Pass --silent to mysqlcheck when in quiet mode.
264+
if ( WP_CLI::get_config( 'quiet' ) ) {
265+
$assoc_args['silent'] = true;
266+
}
267+
262268
self::run(
263269
Utils\esc_cmd( $command, DB_NAME ),
264270
$assoc_args
@@ -307,6 +313,12 @@ public function optimize( $_, $assoc_args ) {
307313
WP_CLI::debug( "Running shell command: {$command}", 'db' );
308314

309315
$assoc_args['optimize'] = true;
316+
317+
// Pass --silent to mysqlcheck when in quiet mode.
318+
if ( WP_CLI::get_config( 'quiet' ) ) {
319+
$assoc_args['silent'] = true;
320+
}
321+
310322
self::run(
311323
Utils\esc_cmd( $command, DB_NAME ),
312324
$assoc_args
@@ -355,6 +367,12 @@ public function repair( $_, $assoc_args ) {
355367
WP_CLI::debug( "Running shell command: {$command}", 'db' );
356368

357369
$assoc_args['repair'] = true;
370+
371+
// Pass --silent to mysqlcheck when in quiet mode.
372+
if ( WP_CLI::get_config( 'quiet' ) ) {
373+
$assoc_args['silent'] = true;
374+
}
375+
358376
self::run(
359377
Utils\esc_cmd( $command, DB_NAME ),
360378
$assoc_args

0 commit comments

Comments
 (0)