OSDN Git Service

implement `wp user get`
authorscribu <mail@scribu.net>
Sun, 14 Jul 2013 13:12:37 +0000 (16:12 +0300)
committerscribu <mail@scribu.net>
Sun, 14 Jul 2013 13:20:54 +0000 (16:20 +0300)
features/user.feature
man-src/user-get.txt [new file with mode: 0644]
php/commands/user.php

index f61d3a1..ee18ec4 100644 (file)
@@ -1,6 +1,6 @@
 Feature: Manage WordPress users
 
-  Scenario: Creating/updating/deleting users
+  Scenario: User CRUD operations
     Given a WP install
 
     When I run `wp user create testuser testuser@example.com --porcelain`
@@ -10,11 +10,12 @@ Feature: Manage WordPress users
     When I try the previous command again
     Then the return code should be 1
 
-    When I run `wp user update {USER_ID} --displayname=Foo`
-    Then STDOUT should be:
-      """
-      Success: Updated user {USER_ID}.
-      """
+    When I run `wp user update {USER_ID} --display_name=Foo`
+    And I run `wp user get {USER_ID}`
+    Then STDOUT should be a table containing rows:
+      | Field        | Value |
+      | ID           | {USER_ID} |
+      | display_name | Foo   |
 
     When I run `wp user delete {USER_ID}`
     Then STDOUT should not be empty
diff --git a/man-src/user-get.txt b/man-src/user-get.txt
new file mode 100644 (file)
index 0000000..9493599
--- /dev/null
@@ -0,0 +1,19 @@
+## OPTIONS
+
+* `[--format=<format>]`:
+
+       The format to use when printing the user; acceptable values:
+
+       **table**: Outputs all fields of the user as a table.
+
+       **json**: Outputs all fields in JSON format.
+
+* `<user>`:
+
+       User ID or user login.
+
+## EXAMPLES
+
+       wp user get 12
+
+       wp user get bob --format=json > bob.json
index eb03e03..b7cbc81 100644 (file)
@@ -57,6 +57,35 @@ class User_Command extends \WP_CLI\CommandWithDBObject {
        }
 
        /**
+        * Get a single user.
+        *
+        * @synopsis [--format=<format>] <user>
+        */
+       public function get( $args, $assoc_args ) {
+               $assoc_args = wp_parse_args( $assoc_args, array(
+                       'format' => 'table'
+               ) );
+
+               $user = self::get_user( $args[0] )->to_array();
+
+               switch ( $assoc_args['format'] ) {
+
+               case 'table':
+                       $this->assoc_array_to_table( $user );
+                       break;
+
+               case 'json':
+                       WP_CLI::print_value( $user, $assoc_args );
+                       break;
+
+               default:
+                       \WP_CLI::error( "Invalid value for format: " . $format );
+                       break;
+
+               }
+       }
+
+       /**
         * Delete one or more users.
         *
         * @synopsis <user>... [--reassign=<id>]