OSDN Git Service

Removed CSV format from `post get`, with JSON format it is redundent, etc.
authorJohn Lamp <j3lamp@gmail.com>
Sun, 14 Apr 2013 00:46:32 +0000 (20:46 -0400)
committerJohn Lamp <j3lamp@gmail.com>
Sun, 14 Apr 2013 00:46:32 +0000 (20:46 -0400)
Removed the `post_content` field from the table format output as the table becomes unweildy and the extremely long value of the content or the content itself causes problems with the table processing. Besides, chances are if one wanted the contents and the other fields JSON would be easier anyway.

features/post.feature
man-src/post-get.txt
man/post-get.1
php/commands/post.php

index 74f6cd8..ee5efed 100644 (file)
@@ -57,17 +57,6 @@ Feature: Manage WordPress posts
       Field    Value
       ID       {POST_ID}
       post_title       Test post
-      post_content     Test content.
-      """
-
-    When I run `wp post get --format=csv {POST_ID}`
-    Then it should run without errors
-    And STDOUT should be a table containing rows:
-      """
-      Field,Value
-      ID,{POST_ID}
-      post_title,"Test post"
-      post_content,"Test content."
       """
 
     When I run `wp post get --format=json {POST_ID}`
index ff20d1d..fab4fde 100644 (file)
@@ -7,9 +7,7 @@
        content: outputs only the post's content (default)
 
        table: output all fields of the post as a table, note that the
-       post_content field is output last to simplify parsing
-
-       csv: output all fields in Comma Separated Value format
+       post_content field is omitted so that the table is readable
 
        json: output all fields in JavaScript Object Notation format
 
index 1a44a82..67511f0 100644 (file)
@@ -21,10 +21,7 @@ The format to use when printing the post, acceptable values:
 content: outputs only the post\'s content (default)
 .
 .IP
-table: output all fields of the post as a table, note that the post_content field is output last to simplify parsing
-.
-.IP
-csv: output all fields in Comma Separated Value format
+table: output all fields of the post as a table, note that the post_content field is omitted so that the table is readable
 .
 .IP
 json: output all fields in JavaScript Object Notation format
index b84d193..d87f903 100644 (file)
@@ -20,7 +20,7 @@ class Post_Command extends \WP_CLI\CommandWithDBObject {
                        if ( $args[0] !== '-' ) {
                                $readfile = $args[0];
                                if ( ! file_exists( $readfile ) || ! is_file( $readfile ) )
-                                        \WP_CLI::error( "Unable to read content from $readfile." );
+                                       \WP_CLI::error( "Unable to read content from $readfile." );
                        } else
                                $readfile = 'php://stdin';
 
@@ -101,31 +101,33 @@ class Post_Command extends \WP_CLI\CommandWithDBObject {
                        break;
 
                case 'table':
-               case 'csv':
                        $items = array();
                        foreach ( get_object_vars( $post ) as $field => $value ) {
                                if ( 'post_content' === $field )
                                        continue;
 
+                               if ( !is_string($value) ) {
+                                       $value = json_encode($value);
+                               }
+
                                $item = new \stdClass;
                                $item->Field = $field;
                                $item->Value = $value;
                                $items[] = $item;
                        }
-                       $content = new \stdClass;
-                       $content->Field = 'post_content';
-                       $content->Value = $post->post_content;
-                       $items[] = $content;
 
                        \WP_CLI\Utils\format_items( $format, array( 'Field', 'Value' ), $items );
                        break;
 
                case 'json':
                        echo( json_encode( $post ) );
+                       echo( "\n" );
                        break;
 
                default:
                        \WP_CLI::error( "Invalid value for format: " . $format );
+                       break;
+
                }
        }