From 124c00501f2c56288591a2064ecb088448599ba9 Mon Sep 17 00:00:00 2001 From: ernilambar Date: Wed, 25 May 2016 17:39:43 +0545 Subject: [PATCH 1/8] introduce --format parameter in cap list --- php/commands/cap.php | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/php/commands/cap.php b/php/commands/cap.php index f5f99d55a8..e63eb1e218 100644 --- a/php/commands/cap.php +++ b/php/commands/cap.php @@ -19,6 +19,10 @@ */ class Capabilities_Command extends WP_CLI_Command { + private $fields = array( + 'name' + ); + /** * List capabilities for a given role. * @@ -27,6 +31,9 @@ class Capabilities_Command extends WP_CLI_Command { * * : Key for the role. * + * [--format=] + * : Accepted values: table, csv, json, count, yaml. Default: table + * * ## EXAMPLES * * # Display alphabetical list of Contributor capabilities @@ -39,11 +46,19 @@ class Capabilities_Command extends WP_CLI_Command { * * @subcommand list */ - public function list_( $args ) { + public function list_( $args, $assoc_args ) { $role_obj = self::get_role( $args[0] ); - foreach ( array_keys( $role_obj->capabilities ) as $cap ) - WP_CLI::line( $cap ); + $output_caps = array(); + foreach ( array_keys( $role_obj->capabilities ) as $cap ) { + $output_cap = new stdClass; + + $output_cap->name = $cap; + + $output_caps[] = $output_cap; + } + $formatter = new \WP_CLI\Formatter( $assoc_args, $this->fields ); + $formatter->display_items( $output_caps ); } /** From 26d1e3299c2947d7c1145b71b42826264fd935f0 Mon Sep 17 00:00:00 2001 From: ernilambar Date: Wed, 25 May 2016 17:49:55 +0545 Subject: [PATCH 2/8] add test scenario for cap list --- features/roles.feature | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/features/roles.feature b/features/roles.feature index 53ac7046ab..5e62fdc846 100644 --- a/features/roles.feature +++ b/features/roles.feature @@ -67,9 +67,10 @@ Feature: Manage WordPress roles | name | role | | Reporter | reporter | - When I run `wp cap list reporter` + When I run `wp cap list reporter --format=csv` Then STDOUT should be: """ + name upload_files edit_posts edit_published_posts @@ -81,3 +82,19 @@ Feature: Manage WordPress roles delete_posts delete_published_posts """ + + When I run `wp cap list reporter` + Then STDOUT should be a table containing rows: + """ + | name | + | upload_files | + | edit_posts | + | edit_published_posts | + | publish_posts | + | read | + | level_2 | + | level_1 | + | level_0 | + | delete_posts | + | delete_published_posts | + """ From 9705f0b0a08b19cc6f8bb7138a9e5897c3e54cd9 Mon Sep 17 00:00:00 2001 From: Nilambar Sharma Date: Wed, 25 May 2016 23:43:16 +0545 Subject: [PATCH 3/8] fix testing of table output --- features/roles.feature | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/features/roles.feature b/features/roles.feature index 5e62fdc846..9f4764af83 100644 --- a/features/roles.feature +++ b/features/roles.feature @@ -86,15 +86,6 @@ Feature: Manage WordPress roles When I run `wp cap list reporter` Then STDOUT should be a table containing rows: """ - | name | - | upload_files | - | edit_posts | - | edit_published_posts | - | publish_posts | - | read | - | level_2 | - | level_1 | - | level_0 | - | delete_posts | - | delete_published_posts | + | name | + | upload_files | """ From 9f7f3cb2ed52e3085c69c146f1630d319e7248b5 Mon Sep 17 00:00:00 2001 From: ernilambar Date: Thu, 26 May 2016 09:18:49 +0545 Subject: [PATCH 4/8] Update doc for cap list as per new standard --- php/commands/cap.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/php/commands/cap.php b/php/commands/cap.php index e63eb1e218..027eccd168 100644 --- a/php/commands/cap.php +++ b/php/commands/cap.php @@ -32,7 +32,17 @@ class Capabilities_Command extends WP_CLI_Command { * : Key for the role. * * [--format=] - * : Accepted values: table, csv, json, count, yaml. Default: table + * : Render output in a particular format. + * --- + * default: list + * options: + * - list + * - table + * - csv + * - json + * - count + * - yaml + * --- * * ## EXAMPLES * From 40c21d52d0f33f071d9f7235d67b8c6ffb4149b1 Mon Sep 17 00:00:00 2001 From: ernilambar Date: Thu, 26 May 2016 09:28:15 +0545 Subject: [PATCH 5/8] Display cap list in list by default --- php/commands/cap.php | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/php/commands/cap.php b/php/commands/cap.php index 027eccd168..90db4a1d90 100644 --- a/php/commands/cap.php +++ b/php/commands/cap.php @@ -59,16 +59,23 @@ class Capabilities_Command extends WP_CLI_Command { public function list_( $args, $assoc_args ) { $role_obj = self::get_role( $args[0] ); - $output_caps = array(); - foreach ( array_keys( $role_obj->capabilities ) as $cap ) { - $output_cap = new stdClass; + if ( ! isset( $assoc_args['format'] ) || in_array( $assoc_args['format'], array( 'list' ) ) ) { + foreach ( array_keys( $role_obj->capabilities ) as $cap ) { + WP_CLI::line( $cap ); + } + } + else { + $output_caps = array(); + foreach ( array_keys( $role_obj->capabilities ) as $cap ) { + $output_cap = new stdClass; - $output_cap->name = $cap; + $output_cap->name = $cap; - $output_caps[] = $output_cap; + $output_caps[] = $output_cap; + } + $formatter = new \WP_CLI\Formatter( $assoc_args, $this->fields ); + $formatter->display_items( $output_caps ); } - $formatter = new \WP_CLI\Formatter( $assoc_args, $this->fields ); - $formatter->display_items( $output_caps ); } /** From dc85b5d35d3311a946b9b72f62c14f774cc57c5d Mon Sep 17 00:00:00 2001 From: ernilambar Date: Thu, 26 May 2016 09:37:39 +0545 Subject: [PATCH 6/8] Fix test of cap list for --format parameter --- features/roles.feature | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/features/roles.feature b/features/roles.feature index 9f4764af83..c4df0c9075 100644 --- a/features/roles.feature +++ b/features/roles.feature @@ -67,10 +67,9 @@ Feature: Manage WordPress roles | name | role | | Reporter | reporter | - When I run `wp cap list reporter --format=csv` + When I run `wp cap list reporter` Then STDOUT should be: """ - name upload_files edit_posts edit_published_posts @@ -83,9 +82,8 @@ Feature: Manage WordPress roles delete_published_posts """ - When I run `wp cap list reporter` - Then STDOUT should be a table containing rows: + When I run `wp cap list reporter --format=count` + Then STDOUT should be: """ - | name | - | upload_files | + 10 """ From d33c8fa31b33f8b87fd864eb602671baacfdd203 Mon Sep 17 00:00:00 2001 From: ernilambar Date: Thu, 26 May 2016 10:09:56 +0545 Subject: [PATCH 7/8] Fix sniffer issue in cap list --- php/commands/cap.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/php/commands/cap.php b/php/commands/cap.php index 90db4a1d90..b89cea9d6f 100644 --- a/php/commands/cap.php +++ b/php/commands/cap.php @@ -61,7 +61,7 @@ public function list_( $args, $assoc_args ) { if ( ! isset( $assoc_args['format'] ) || in_array( $assoc_args['format'], array( 'list' ) ) ) { foreach ( array_keys( $role_obj->capabilities ) as $cap ) { - WP_CLI::line( $cap ); + WP_CLI::line( $cap ); } } else { From 76a9d418bcf72080db92dfcea2982d74d90c720b Mon Sep 17 00:00:00 2001 From: Nilambar Sharma Date: Thu, 26 May 2016 21:31:37 +0545 Subject: [PATCH 8/8] modify conditionals in cap list --- php/commands/cap.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/php/commands/cap.php b/php/commands/cap.php index b89cea9d6f..0663f248e4 100644 --- a/php/commands/cap.php +++ b/php/commands/cap.php @@ -59,7 +59,7 @@ class Capabilities_Command extends WP_CLI_Command { public function list_( $args, $assoc_args ) { $role_obj = self::get_role( $args[0] ); - if ( ! isset( $assoc_args['format'] ) || in_array( $assoc_args['format'], array( 'list' ) ) ) { + if ( 'list' === $assoc_args['format'] ) { foreach ( array_keys( $role_obj->capabilities ) as $cap ) { WP_CLI::line( $cap ); }