From a9994f863f06d6b904636a46ffb22ac6e7fa7927 Mon Sep 17 00:00:00 2001 From: Nilambar Sharma Date: Tue, 13 Aug 2024 11:52:45 +0545 Subject: [PATCH 1/2] Correct error message for count format --- src/DB_Command.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DB_Command.php b/src/DB_Command.php index 2023e5db..1a47eb14 100644 --- a/src/DB_Command.php +++ b/src/DB_Command.php @@ -1553,7 +1553,7 @@ public function search( $args, $assoc_args ) { if ( in_array( $format, [ 'ids', 'count' ], true ) ) { if ( count( $tables ) > 1 ) { - WP_CLI::error( 'The "ids" format can only be used for a single table.' ); + WP_CLI::error( "The \"{$format}\" format can only be used for a single table." ); } $search_results = array_column( $search_results, 'primary_key_value' ); } From 176dc7524612fc35d01517eae8c9eb22eb7b5820 Mon Sep 17 00:00:00 2001 From: Nilambar Sharma Date: Tue, 13 Aug 2024 11:54:00 +0545 Subject: [PATCH 2/2] Add feature test for correct error message --- features/db-search.feature | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/features/db-search.feature b/features/db-search.feature index 8734dc13..01b28861 100644 --- a/features/db-search.feature +++ b/features/db-search.feature @@ -1102,5 +1102,13 @@ Feature: Search through the database And STDOUT should be empty And the return code should be 1 + When I try `wp db search example.com --format=count` + Then STDERR should be: + """ + Error: The "count" format can only be used for a single table. + """ + And STDOUT should be empty + And the return code should be 1 + When I run `wp db search mail.example.com wp_options --format=ids` Then STDOUT should not be empty