OSDN Git Service

role: Update role list to properly format roles in a table
authorDaniel Bachhuber <d@danielbachhuber.com>
Tue, 12 Mar 2013 02:50:52 +0000 (19:50 -0700)
committerDaniel Bachhuber <d@danielbachhuber.com>
Tue, 12 Mar 2013 02:50:52 +0000 (19:50 -0700)
man-src/role-list.txt
php/commands/role.php

index 6bc9ed2..a2dcd0c 100644 (file)
@@ -1,3 +1,9 @@
+## OPTIONS
+
+* `--format`=<format>:
+
+       Output list as table, CSV or JSON. Defaults to table.
+
 ## EXAMPLES
 
     wp role list
index 4c1104e..8f2e076 100644 (file)
@@ -11,13 +11,32 @@ class Role_Command extends WP_CLI_Command {
         * List all roles.
         *
         * @subcommand list
+        * @synopsis [--format=<format>]
         */
-       public function _list( $args ) {
+       public function _list( $args, $assoc_args ) {
                global $wp_roles;
 
+               $defaults = array(
+                       'format'    => 'table',
+               );
+               $params = array_merge( $defaults, $assoc_args );
+
+               $fields = array(
+                               'name',
+                               'role',
+                       );
+
+               $output_roles = array();
                foreach ( $wp_roles->roles as $key => $role ) {
-                               WP_CLI::line( $role['name'] . " ($key)");
+                       $output_role = new stdClass;
+
+                       $output_role->name = $role['name'];
+                       $output_role->role = $key;
+
+                       $output_roles[] = $output_role;
                }
+
+               WP_CLI\Utils\format_items( $params['format'], $fields, $output_roles );
        }
 
        /**