From 5ca96a8f327bf2d63924359377ecd2b46a7ccac2 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 9 Dec 2025 14:00:48 +0000 Subject: [PATCH 1/5] Initial plan From 052f48da7b3abd56f8d40c603ab129ff9b78f188 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 9 Dec 2025 14:09:08 +0000 Subject: [PATCH 2/5] Fix Formatter to display boolean false as "0" in table/CSV formats Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- features/formatter.feature | 52 ++++++++++++++++++++++++++++++++++++++ php/WP_CLI/Formatter.php | 7 +++++ 2 files changed, 59 insertions(+) diff --git a/features/formatter.feature b/features/formatter.feature index 62753cbd08..52cb5e9ac7 100644 --- a/features/formatter.feature +++ b/features/formatter.feature @@ -189,3 +189,55 @@ Feature: Format output | | | banana | | | | mango | | 1 | bar | br | + + Scenario: Format boolean values in table and JSON + Given an empty directory + And a file.php file: + """ + 1, + 'status' => true, + ), + array( + 'id' => 2, + 'status' => false, + ), + ); + $assoc_args = array(); + $formatter = new WP_CLI\Formatter( $assoc_args, array( 'id', 'status' ) ); + $formatter->display_items( $items ); + """ + + When I run `wp eval-file file.php --skip-wordpress` + Then STDOUT should be a table containing rows: + | id | status | + | 1 | 1 | + | 2 | 0 | + + Scenario: Format boolean values as JSON preserves boolean type + Given an empty directory + And a file.php file: + """ + 1, + 'status' => true, + ), + array( + 'id' => 2, + 'status' => false, + ), + ); + $assoc_args = array( 'format' => 'json' ); + $formatter = new WP_CLI\Formatter( $assoc_args, array( 'id', 'status' ) ); + $formatter->display_items( $items ); + """ + + When I run `wp eval-file file.php --skip-wordpress` + Then STDOUT should be JSON containing: + """ + [{"id":1,"status":true},{"id":2,"status":false}] + """ diff --git a/php/WP_CLI/Formatter.php b/php/WP_CLI/Formatter.php index 87480a24a9..d474e955a2 100644 --- a/php/WP_CLI/Formatter.php +++ b/php/WP_CLI/Formatter.php @@ -371,6 +371,13 @@ public function transform_item_values_to_json( $item ) { } elseif ( is_array( $item ) ) { $item[ $true_field ] = json_encode( $value ); } + } elseif ( is_bool( $value ) ) { + // Convert boolean to string representation for table/CSV display + if ( is_object( $item ) ) { + $item->$true_field = $value ? '1' : '0'; + } elseif ( is_array( $item ) ) { + $item[ $true_field ] = $value ? '1' : '0'; + } } } return $item; From fe8655de44db7ddf4e24071288830b014f2efa0c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 9 Dec 2025 14:10:49 +0000 Subject: [PATCH 3/5] Update docstring for transform_item_values_to_json to reflect boolean handling Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- php/WP_CLI/Formatter.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/php/WP_CLI/Formatter.php b/php/WP_CLI/Formatter.php index d474e955a2..18c85c9f7a 100644 --- a/php/WP_CLI/Formatter.php +++ b/php/WP_CLI/Formatter.php @@ -356,7 +356,11 @@ private function assoc_array_to_rows( $fields ) { } /** - * Transforms objects and arrays to JSON as necessary + * Transforms item values for string-based output formats (table/CSV). + * + * Converts complex types to strings: + * - Objects and arrays are converted to JSON strings + * - Booleans are converted to "1" or "0" * * @param array|object $item * @return mixed From 00d9a24fc865c2912774d4708a30b01e5cd976df Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 11 Jan 2026 17:12:35 +0000 Subject: [PATCH 4/5] Use 'true'/'false' instead of '1'/'0' for boolean string representation Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- features/formatter.feature | 4 ++-- php/WP_CLI/Formatter.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/features/formatter.feature b/features/formatter.feature index 52cb5e9ac7..b7eedb1623 100644 --- a/features/formatter.feature +++ b/features/formatter.feature @@ -213,8 +213,8 @@ Feature: Format output When I run `wp eval-file file.php --skip-wordpress` Then STDOUT should be a table containing rows: | id | status | - | 1 | 1 | - | 2 | 0 | + | 1 | true | + | 2 | false | Scenario: Format boolean values as JSON preserves boolean type Given an empty directory diff --git a/php/WP_CLI/Formatter.php b/php/WP_CLI/Formatter.php index 18c85c9f7a..e808005b70 100644 --- a/php/WP_CLI/Formatter.php +++ b/php/WP_CLI/Formatter.php @@ -378,9 +378,9 @@ public function transform_item_values_to_json( $item ) { } elseif ( is_bool( $value ) ) { // Convert boolean to string representation for table/CSV display if ( is_object( $item ) ) { - $item->$true_field = $value ? '1' : '0'; + $item->$true_field = $value ? 'true' : 'false'; } elseif ( is_array( $item ) ) { - $item[ $true_field ] = $value ? '1' : '0'; + $item[ $true_field ] = $value ? 'true' : 'false'; } } } From 4a8c938c707e9fd47ead1a1db5dde7098727ed63 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 11 Jan 2026 17:13:12 +0000 Subject: [PATCH 5/5] Update docstring to reflect 'true'/'false' boolean representation Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- php/WP_CLI/Formatter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/php/WP_CLI/Formatter.php b/php/WP_CLI/Formatter.php index e808005b70..ce17fe35b8 100644 --- a/php/WP_CLI/Formatter.php +++ b/php/WP_CLI/Formatter.php @@ -360,7 +360,7 @@ private function assoc_array_to_rows( $fields ) { * * Converts complex types to strings: * - Objects and arrays are converted to JSON strings - * - Booleans are converted to "1" or "0" + * - Booleans are converted to "true" or "false" * * @param array|object $item * @return mixed