OSDN Git Service

help --gen: add test for third-party commands
authorscribu <mail@scribu.net>
Mon, 20 May 2013 13:53:44 +0000 (16:53 +0300)
committerscribu <mail@scribu.net>
Mon, 20 May 2013 13:54:37 +0000 (16:54 +0300)
.travis.yml
features/help.feature
features/steps/basic_steps.php
php/class-wp-cli.php
php/commands/help.php
php/man.php

index 622e25b..d0a9ceb 100644 (file)
@@ -17,6 +17,7 @@ before_script:
     # install dependencies
     - composer install --dev --no-interaction --prefer-source
     - composer require d11wtq/boris=dev-master --no-interaction --prefer-source
+    - gem install ronn
     # set up WP install
     - bin/wp core download --version=$WP_VERSION --path=/tmp/wp-cli-test-core-download-cache/
     # set up database
index 205cd8b..7ee24d6 100644 (file)
@@ -33,7 +33,13 @@ Feature: Get help about WP-CLI commands
 
   Scenario: Getting help for a third-party command
     Given a WP install
-    And a wp-content/plugins/test-cli-help.php file:
+    And a wp-content/plugins/test-cli/test-help.txt file:
+      """
+      ## EXAMPLES
+
+          wp test-help
+      """
+    And a wp-content/plugins/test-cli/command.php file:
       """
       <?php
       // Plugin Name: Test CLI Help
@@ -43,8 +49,10 @@ Feature: Get help about WP-CLI commands
       }
 
       WP_CLI::add_command( 'test-help', 'Test_Help' );
+
+      WP_CLI::add_man_dir( __DIR__, __DIR__ );
       """
-    And I run `wp plugin activate test-cli-help`
+    And I run `wp plugin activate test-cli`
 
     When I run `wp help test-help`
     Then STDOUT should contain:
@@ -52,7 +60,19 @@ Feature: Get help about WP-CLI commands
       usage: wp test-help
       """
 
-  Scenario: Generating help
+    When I run `wp help --gen test-help`
+    Then STDOUT should contain:
+      """
+      generated test-help.1
+      """
+
+    When I run `wp help test-help`
+    Then STDOUT should contain:
+      """
+      WP-TEST-HELP(1)
+      """
+
+  Scenario: Generating help for multisite-only subcommands
     Given an empty directory
     When I run `wp help --gen blog create`
     Then STDOUT should be:
index d5432db..f838df6 100644 (file)
@@ -23,7 +23,9 @@ $steps->Given( '/^an empty directory$/',
 $steps->Given( '/^a ([^\s]+) file:$/',
        function ( $world, $path, PyStringNode $content ) {
                $content = (string) $content . "\n";
-               file_put_contents( $world->get_path( $path ), $content );
+               $full_path = $world->get_path( $path );
+               Process::create( \WP_CLI\utils\esc_cmd( 'mkdir -p %s', dirname( $full_path ) ) )->run_check();
+               file_put_contents( $full_path, $content );
        }
 );
 
index a711d4d..1a47614 100644 (file)
@@ -19,8 +19,8 @@ class WP_CLI {
         */
        static function init() {
                self::add_man_dir(
-                       WP_CLI_ROOT . "../man/",
-                       WP_CLI_ROOT . "../man-src/"
+                       WP_CLI_ROOT . "../man",
+                       WP_CLI_ROOT . "../man-src"
                );
 
                self::$root = new Dispatcher\RootCommand;
index c66e4a9..9043a7e 100644 (file)
@@ -41,16 +41,17 @@ class Help_Command extends WP_CLI_Command {
 
                $command = WP_CLI\Utils\find_subcommand( $args );
 
-               if ( !$command ) {
-                       WP_CLI::error( sprintf( "'%s' command not found.",
-                               implode( ' ', $arg_copy ) ) );
+               if ( $command ) {
+                       foreach ( WP_CLI::get_man_dirs() as $dest_dir => $src_dir ) {
+                               WP_CLI\Man\generate( $src_dir, $dest_dir, $command );
+                       }
+                       exit;
                }
 
-               foreach ( WP_CLI::get_man_dirs() as $dest_dir => $src_dir ) {
-                       WP_CLI\Man\generate( $src_dir, $dest_dir, $command );
+               // WordPress is already loaded, so there's no chance we'll find the command
+               if ( function_exists( 'add_filter' ) ) {
+                       WP_CLI::error( sprintf( "'%s' command not found.", implode( ' ', $arg_copy ) ) );
                }
-
-               exit;
        }
 }
 
index 0d42cbf..38abf2d 100644 (file)
@@ -16,8 +16,8 @@ function generate( $src_dir, $dest_dir, $command ) {
        $cmd_path = Dispatcher\get_path( $command );
        array_shift( $cmd_path ); // discard 'wp'
 
-       $src_path = $src_dir . get_src_file_name( $cmd_path );
-       $dest_path = $dest_dir . get_file_name( $cmd_path );
+       $src_path = "$src_dir/" . get_src_file_name( $cmd_path );
+       $dest_path = "$dest_dir/" . get_file_name( $cmd_path );
 
        call_ronn( get_markdown( $src_path, $command ), $dest_path );
 
@@ -134,7 +134,7 @@ function maybe_show_manpage( $args ) {
        $man_file = get_file_name( $args );
 
        foreach ( \WP_CLI::get_man_dirs() as $dest_dir => $_ ) {
-               $man_path = $dest_dir . $man_file;
+               $man_path = "$dest_dir/" . $man_file;
 
                if ( is_readable( $man_path ) ) {
                        show_manpage( $man_path );