Formatter prints empty string for boolean with `false` value
Bug Report
- Yes, I reviewed the contribution guidelines.
- Yes, more specifically, I reviewed the guidelines on how to write clear bug reports.
The following code prints the following output:
$formatter = new \WP_CLI\Formatter($assocArgs, [ 'id', 'status', ]); $entries = [ [ 'id' => 1, 'status' => true, ], [ 'id' => 2, 'status' => false, ] ]; $iterator = \WP_CLI\Utils\iterator_map( $entries, function (array $entry) { return $entry; } ); $formatter->display_items($iterator);
Output:
+----+--------+
| id | status |
+----+--------+
| 1 | 1 |
| 2 | |
+----+--------+
I would have expected something like:
+----+--------+
| id | status |
+----+--------+
| 1 | 1 |
| 2 | 0 |
+----+--------+
or even better:
+----+--------+
| id | status |
+----+--------+
| 1 | true |
| 2 | false |
+----+--------+
I tried something like this to change the output, but the problem is that I would still like a boolean if I output a json with --format=json.
$iterator = \WP_CLI\Utils\iterator_map( $entries, function (array $entry) { $entry['status'] = $entry['status'] ? 'true' : 'false'; return $entry; } );