OSDN Git Service

move OS detection to launch_editor_for_input()
authorscribu <mail@scribu.net>
Mon, 28 Oct 2013 19:43:15 +0000 (21:43 +0200)
committerscribu <mail@scribu.net>
Mon, 28 Oct 2013 19:43:28 +0000 (21:43 +0200)
see #822

php/commands/post.php
php/utils.php

index 0dfc276..c4d8f24 100644 (file)
@@ -123,8 +123,7 @@ class Post_Command extends \WP_CLI\CommandWithDBObject {
 
        protected function _edit( $content, $title ) {
                $content = apply_filters( 'the_editor_content', $content );
-               $os = strpos( $_SERVER['OS'], 'indows' )===false ? 'linux' : 'windows';
-               $output = \WP_CLI\Utils\launch_editor_for_input( $content, $title, $os );
+               $output = \WP_CLI\Utils\launch_editor_for_input( $content, $title );
                return ( is_string( $output ) ) ?
                        apply_filters( 'content_save_pre', $output ) : $output;
        }
index 1b7d956..23f6d5e 100644 (file)
@@ -256,7 +256,7 @@ function pick_fields( $item, $fields ) {
  * @return str|bool       Edited text, if file is saved from editor
  *                        False, if no change to file
  */
-function launch_editor_for_input( $input, $title = 'WP-CLI', $os='linux' ) {
+function launch_editor_for_input( $input, $title = 'WP-CLI' ) {
 
        $tmpfile = wp_tempnam( $title );
 
@@ -266,10 +266,15 @@ function launch_editor_for_input( $input, $title = 'WP-CLI', $os='linux' ) {
        $output = '';
        file_put_contents( $tmpfile, $input );
 
-       if( $os==='linux' )
-       \WP_CLI::launch( "\${EDITOR:-vi} '$tmpfile'" );
-       else
-               exec("notepad $tmpfile" );
+       $editor = getenv( 'EDITOR' );
+       if ( !$editor ) {
+               if ( isset( $_SERVER['OS'] ) && false !== strpos( $_SERVER['OS'], 'indows' ) )
+                       $editor = 'notepad';
+               else
+                       $editor = 'vi';
+       }
+
+       \WP_CLI::launch( \WP_CLI\Utils\esc_cmd( "$editor %s", $tmpfile ) );
 
        $output = file_get_contents( $tmpfile );