OSDN Git Service

show synopsis for incomplete commands, even without a WP install
authorscribu <mail@scribu.net>
Tue, 23 Jul 2013 21:02:35 +0000 (00:02 +0300)
committerscribu <mail@scribu.net>
Tue, 23 Jul 2013 21:02:35 +0000 (00:02 +0300)
features/help.feature
php/WP_CLI/Runner.php

index 2f21935..3aef3db 100644 (file)
@@ -47,3 +47,12 @@ Feature: Get help about WP-CLI commands
       """
       wp test-help
       """
+
+  Scenario: Help for incomplete commands
+    Given an empty directory
+
+    When I run `wp core`
+    Then STDOUT should contain:
+      """
+      usage: wp core
+      """
index 8af6b2a..515f75d 100644 (file)
@@ -158,17 +158,17 @@ class Runner {
                        $subcommand = $command->find_subcommand( $args );
 
                        if ( !$subcommand ) {
-                               \WP_CLI::error( sprintf(
+                               return sprintf(
                                        "'%s' is not a registered wp command. See 'wp help'.",
                                        $full_name
-                               ) );
+                               );
                        }
 
                        if ( in_array( $full_name, $disabled_commands ) ) {
-                               \WP_CLI::error( sprintf(
+                               return sprintf(
                                        "The '%s' command has been disabled from the config file.",
                                        $full_name
-                               ) );
+                               );
                        }
 
                        $command = $subcommand;
@@ -178,7 +178,12 @@ class Runner {
        }
 
        public function run_command( $args, $assoc_args = array() ) {
-               list( $command, $final_args ) = $this->find_command_to_run( $args );
+               $r = $this->find_command_to_run( $args );
+               if ( is_string( $r ) ) {
+                       WP_CLI::error( $r );
+               }
+
+               list( $command, $final_args ) = $r;
 
                $command->invoke( $final_args, $assoc_args );
        }
@@ -368,6 +373,17 @@ class Runner {
                        }
                }
 
+               // Show synopsis if it's a composite command.
+               $r = $this->find_command_to_run( $args );
+               if ( is_array( $r ) ) {
+                       list( $command ) = $r;
+
+                       if ( $command->has_subcommands() ) {
+                               $command->show_usage();
+                               exit;
+                       }
+               }
+
                // First try at showing man page
                if ( $this->cmd_starts_with( array( 'help' ) ) ) {
                        $this->_run_command();