-
Notifications
You must be signed in to change notification settings - Fork 312
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a --pretty flag to WP-CLI get-mapping + docs #2653
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, it would be good to add that flag to other methods as well.
@oscarssanchez added the flag to the other commands and assigning back to you for the final review. Thanks for the suggestion! |
includes/classes/Command.php
Outdated
@@ -1023,8 +1039,9 @@ public function get_last_cli_index( $args, $assoc_args ) { | |||
delete_site_option( 'ep_last_cli_index' ); | |||
} | |||
|
|||
WP_CLI::line( wp_json_encode( $last_sync ) ); | |||
$flag = ( ! empty( $assoc_args['pretty'] ) ) ? JSON_PRETTY_PRINT : null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1042-1044 are similar to 1013-1015 and somewhat similar to 1471 and 1474 is there a way we could make it more DRY? maybe splitting print_json_response()
into two functions, one that prints the JSON based on the pretty flag, and other that processes the response/option data ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought about that and wondered if it wouldn't be an overengineering but you are right. I've pushed a new commit addressing that (and also passing arguments to get_indexing_status()
as that wasn't working properly). Do you mind checking it again, @oscarssanchez ? Thanks!
Description of the Change
Currently, the
get-mapping
WP-CLI command just outputs the raw response from Elasticsearch, an unformatted JSON string. This PR introduces a--pretty
flag, where the JSON is broken into several lines and receives some indentation, making things easier to read.As this is a new feature, I'm adding it to the
4.1.0
milestone.Changelog Entry
Added: new
--pretty
flag to the WP-CLI commands that output a JSON.Credits
Props @felipeelia and @oscarssanchez