Skip to content

Commit 0ac574b

Browse files
CopilotswissspidyCopilot
authored
Add more verbose debug output (#207)
* Initial plan * Add --verbose flag for doctor check command Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> * Extract magic number to named constant Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> * Fix test: use file-based check instead of php-in-upload Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> * Update features/check.feature Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Change file count wording to "items visited" for accuracy Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> * Suppress verbose mode for non-table formats to prevent output corruption Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> * Replace --verbose flag with WP_CLI::debug() using --debug=doctor Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> * Update tests --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> Co-authored-by: Pascal Birchler <pascal.birchler@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Pascal Birchler <pascalb@google.com>
1 parent a507d68 commit 0ac574b

2 files changed

Lines changed: 64 additions & 0 deletions

File tree

features/check.feature

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,3 +185,49 @@ Feature: Basic check usage
185185
And STDOUT should be a table containing rows:
186186
| name | status |
187187
| autoload-options-size | success |
188+
189+
Scenario: Use --debug=doctor flag to see check progress
190+
Given a WP install
191+
192+
When I try `wp doctor check autoload-options-size --debug=doctor`
193+
Then STDERR should contain:
194+
"""
195+
Running check: autoload-options-size
196+
"""
197+
And STDERR should contain:
198+
"""
199+
Status:
200+
"""
201+
202+
Scenario: Use --debug=doctor flag with multiple checks
203+
Given a WP install
204+
205+
When I try `wp doctor check autoload-options-size plugin-deactivated --debug=doctor`
206+
Then STDERR should contain:
207+
"""
208+
Running check: autoload-options-size
209+
"""
210+
And STDERR should contain:
211+
"""
212+
Running check: plugin-deactivated
213+
"""
214+
215+
Scenario: Use --debug=doctor flag with file checks
216+
Given a WP install
217+
And a wp-content/plugins/foo.php file:
218+
"""
219+
<?php
220+
// Plugin Name: Foo Plugin
221+
222+
wp_cache_flush();
223+
"""
224+
225+
When I try `wp doctor check cache-flush --debug=doctor`
226+
Then STDERR should contain:
227+
"""
228+
Scanning filesystem for file checks...
229+
"""
230+
And STDERR should contain:
231+
"""
232+
Running check: cache-flush
233+
"""

src/Command.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@
3636
*/
3737
class Command {
3838

39+
/**
40+
* Number of files to scan before showing progress in debug mode.
41+
*/
42+
const DEBUG_FILE_SCAN_INTERVAL = 1000;
43+
3944
/**
4045
* Run a series of checks against WordPress to diagnose issues.
4146
*
@@ -134,11 +139,14 @@ public function check( $args, $assoc_args ) {
134139
WP_CLI::add_hook(
135140
$when,
136141
static function () use ( $name, $check, &$completed, &$progress ) {
142+
WP_CLI::debug( "Running check: {$name}", 'doctor' );
137143
$check->run();
138144
$completed[ $name ] = $check;
139145
if ( $progress ) {
140146
$progress->tick();
141147
}
148+
$results = $check->get_results();
149+
WP_CLI::debug( " Status: {$results['status']}", 'doctor' );
142150
}
143151
);
144152
} else {
@@ -152,11 +160,17 @@ static function () use ( $name, $check, &$completed, &$progress ) {
152160
WP_CLI::add_hook(
153161
'after_wp_config_load',
154162
static function () use ( $file_checks, &$completed, &$progress ) {
163+
WP_CLI::debug( 'Scanning filesystem for file checks...', 'doctor' );
155164
try {
156165
$directory = new RecursiveDirectoryIterator( ABSPATH, RecursiveDirectoryIterator::SKIP_DOTS );
157166
$iterator = new RecursiveIteratorIterator( $directory, RecursiveIteratorIterator::CHILD_FIRST );
158167
$wp_content_dir = defined( 'WP_CONTENT_DIR' ) ? WP_CONTENT_DIR : ABSPATH . 'wp-content';
168+
$item_count = 0;
159169
foreach ( $iterator as $file ) {
170+
++$item_count;
171+
if ( 0 === $item_count % self::DEBUG_FILE_SCAN_INTERVAL ) {
172+
WP_CLI::debug( " Visited {$item_count} items...", 'doctor' );
173+
}
160174
foreach ( $file_checks as $name => $check ) {
161175
$options = $check->get_options();
162176
if ( ! empty( $options['only_wp_content'] )
@@ -174,15 +188,19 @@ static function () use ( $file_checks, &$completed, &$progress ) {
174188
$check->check_file( $file );
175189
}
176190
}
191+
WP_CLI::debug( " Total items visited: {$item_count}", 'doctor' );
177192
} catch ( Exception $e ) {
178193
WP_CLI::warning( $e->getMessage() );
179194
}
180195
foreach ( $file_checks as $name => $check ) {
196+
WP_CLI::debug( "Running check: {$name}", 'doctor' );
181197
$check->run();
182198
$completed[ $name ] = $check;
183199
if ( $progress ) {
184200
$progress->tick();
185201
}
202+
$results = $check->get_results();
203+
WP_CLI::debug( " Status: {$results['status']}", 'doctor' );
186204
}
187205
}
188206
);

0 commit comments

Comments
 (0)