Skip to content

Commit 0f0586c

Browse files
committed
fix: improve error handling output format in checksum verification
1 parent 23856fb commit 0f0586c

1 file changed

Lines changed: 17 additions & 6 deletions

File tree

src/Checksum_Core_Command.php

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,8 @@ class Checksum_Core_Command extends Checksum_Base_Command {
6363
* : Exclude specific files from the checksum verification. Provide a comma-separated list of file paths.
6464
*
6565
* [--format=<format>]
66-
* : Render output in a specific format.
66+
* : Render output in a specific format. When provided, errors are displayed in tabular format instead of individual warning messages.
6767
* ---
68-
* default: table
6968
* options:
7069
* - table
7170
* - json
@@ -161,14 +160,22 @@ public function __invoke( $args, $assoc_args ) {
161160
}
162161

163162
if ( ! file_exists( ABSPATH . $file ) ) {
164-
$this->add_error( $file, "File doesn't exist" );
163+
if ( isset( $assoc_args['format'] ) ) {
164+
$this->add_error( $file, "File doesn't exist" );
165+
} else {
166+
WP_CLI::warning( "File doesn't exist: {$file}" );
167+
}
165168
$has_errors = true;
166169
continue;
167170
}
168171

169172
$md5_file = md5_file( ABSPATH . $file );
170173
if ( $md5_file !== $checksum ) {
171-
$this->add_error( $file, "File doesn't verify against checksum" );
174+
if ( isset( $assoc_args['format'] ) ) {
175+
$this->add_error( $file, "File doesn't verify against checksum" );
176+
} else {
177+
WP_CLI::warning( "File doesn't verify against checksum: {$file}" );
178+
}
172179
$has_errors = true;
173180
}
174181
}
@@ -182,11 +189,15 @@ public function __invoke( $args, $assoc_args ) {
182189
if ( in_array( $additional_file, $this->exclude_files, true ) ) {
183190
continue;
184191
}
185-
$this->add_error( $additional_file, 'File should not exist' );
192+
if ( isset( $assoc_args['format'] ) ) {
193+
$this->add_error( $additional_file, 'File should not exist' );
194+
} else {
195+
WP_CLI::warning( "File should not exist: {$additional_file}" );
196+
}
186197
}
187198
}
188199

189-
if ( ! empty( $this->errors ) ) {
200+
if ( ! empty( $this->errors ) && isset( $assoc_args['format'] ) ) {
190201
$formatter = new Formatter(
191202
$assoc_args,
192203
array( 'file', 'message' )

0 commit comments

Comments
 (0)