Skip to content

Formatter prints empty string for boolean with false value #5542

@korridor

Description

@korridor

Bug Report

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;
    }
);

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions