From: goldenapples Date: Fri, 15 Feb 2013 00:18:59 +0000 (-0800) Subject: Allow `wp post create` to read from file or STDIN X-Git-Tag: v0.9.0~87^2~3 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=c47fafe50b83d555f1cb257b2bc91393b2642d37;p=wvm%2Fwvm.git Allow `wp post create` to read from file or STDIN If a filename is passed as the first argument to `wp post create`, that file will be read for the post's content. If the first argument is '-', then post content will be read from STDIN. If an unreadable filename is given, `wp post create` exits with an error. --- diff --git a/php/commands/post.php b/php/commands/post.php index 625f3306..fe795072 100644 --- a/php/commands/post.php +++ b/php/commands/post.php @@ -12,9 +12,17 @@ class Post_Command extends \WP_CLI\CommandWithDBObject { /** * Create a post. * - * @synopsis --= [--edit] [--porcelain] + * @synopsis [] --= [--porcelain] */ - public function create( $_, $assoc_args ) { + public function create( $args, $assoc_args ) { + if ( ! empty( $args[0] ) ) { + $readfile = ( $args[0] === '-' ) ? 'php://stdin' : $args[0]; + + if ( ! file_exists( $readfile ) || ! is_file( $readfile ) ) + \WP_CLI::error( "Unable to read content from $readfile." ); + + $assoc_args['post_content'] = file_get_contents( $readfile ); + } if ( isset( $assoc_args['edit'] ) ) { $input = ( isset( $assoc_args['post_content'] ) ) ? @@ -26,7 +34,6 @@ class Post_Command extends \WP_CLI\CommandWithDBObject { $assoc_args['post_content'] = $input; } - parent::create( $assoc_args ); }