wp-cli / entity-command

Manage WordPress comments, menus, options, posts, sites, terms, and users.
MIT License
100 stars 89 forks source link

Introduce `--format=ids` in user application password list #475

Closed ernilambar closed 4 months ago

ernilambar commented 6 months ago

Fixes https://github.com/wp-cli/entity-command/issues/474

ernilambar commented 6 months ago

@swissspidy In Formatter, $assoc_args is passed by reference.

public function __construct( &$assoc_args, $fields = null, $prefix = false ) {

And it unsets the format key in the method. https://github.com/wp-cli/wp-cli/blob/main/php/WP_CLI/Formatter.php#L46

So, if we keep $formatter = new Formatter( $assoc_args, $fields ); before the conditional, if condition will never be true because we now dont have $assoc_args['format'].

ernilambar commented 6 months ago

cc @danielbachhuber

schlessera commented 6 months ago

@ernilambar I suggest to go with the tweak that @swissspidy mentioned but also combine it with an early processing of the flag like so:

$format = Utils\get_flag_value( $assoc_args, 'format', 'table' );

This will avoid the breakage with @swissspidy 's refactor, and it will also make the conditional(s) cleaner.