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.
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}`
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
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
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';
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;
+
}
}