From aca91d24968dd21181ede202ad049e0728edb67f Mon Sep 17 00:00:00 2001 From: scribu Date: Tue, 1 Oct 2013 01:58:30 +0300 Subject: [PATCH] rename `wp rewrite dump` to `wp rewrite list` ... and make its output consistent with the rest of the commands --- php/commands/rewrite.php | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/php/commands/rewrite.php b/php/commands/rewrite.php index 8b8ebc55..27888bd0 100644 --- a/php/commands/rewrite.php +++ b/php/commands/rewrite.php @@ -94,35 +94,31 @@ class Rewrite_Command extends WP_CLI_Command { * ## OPTIONS * * [--format=] - * : Output list as JSON. Defaults to tab-separated lines. + * : Output list as table, JSON or CSV. Defaults to table. * * ## EXAMPLES * - * wp rewrite dump --format=json + * wp rewrite list --format=csv + * @subcommand list */ - public function dump( $args, $assoc_args ) { + public function _list( $args, $assoc_args ) { $rules = get_option( 'rewrite_rules' ); if ( ! $rules ) { $rules = array(); WP_CLI::warning( 'No rewrite rules.' ); } + $defaults = array( - 'format' => '' + 'format' => 'table' ); $assoc_args = array_merge( $defaults, $assoc_args ); - switch ( $assoc_args['format'] ) { - - case 'json': - echo json_encode( $rules ); - break; - - default: - foreach ( $rules as $route => $rule ) - WP_CLI::line( $route . "\t" . $rule ); - break; - + $rule_list = array(); + foreach ( $rules as $match => $query ) { + $rule_list[] = compact( 'match', 'query' ); } + + WP_CLI\Utils\format_items( $assoc_args['format'], $rule_list, array('match', 'query') ); } /** -- 2.11.0