OSDN Git Service

convert `wp --man` to `wp help --gen`
authorscribu <mail@scribu.net>
Mon, 20 May 2013 12:20:07 +0000 (15:20 +0300)
committerscribu <mail@scribu.net>
Mon, 20 May 2013 12:20:07 +0000 (15:20 +0300)
php/WP_CLI/Dispatcher/RootCommand.php
php/WP_CLI/InternalFlags.php
php/WP_CLI/Runner.php
php/commands/help.php

index 0da342d..4c74f82 100644 (file)
@@ -73,11 +73,6 @@ EOB
        }
 
        function pre_invoke( &$args ) {
-               if ( array( 'help' ) == $args ) {
-                       $this->show_usage();
-                       exit;
-               }
-
                $cmd_name = $args[0];
 
                $command = $this->find_subcommand( $args );
index 87cabf3..1f5bf70 100644 (file)
@@ -55,27 +55,5 @@ class InternalFlags {
                        WP_CLI::line( $name . ' ' . implode( ' ', array_keys( $subcommands ) ) );
                }
        }
-
-       static function man( $args ) {
-               if ( '' === exec( 'which ronn' ) ) {
-                       WP_CLI::error( '`ronn` executable not found.' );
-               }
-
-               $arg_copy = $args;
-
-               $command = WP_CLI::$root;
-
-               while ( !empty( $args ) && $command && $command instanceof Dispatcher\CommandContainer ) {
-                       $command = $command->find_subcommand( $args );
-               }
-
-               if ( !$command )
-                       WP_CLI::error( sprintf( "'%s' command not found.",
-                               implode( ' ', $arg_copy ) ) );
-
-               foreach ( WP_CLI::get_man_dirs() as $dest_dir => $src_dir ) {
-                       WP_CLI\Man\generate( $src_dir, $dest_dir, $command );
-               }
-       }
 }
 
index 106fc64..1079637 100644 (file)
@@ -163,12 +163,6 @@ class Runner {
        }
 
        private function _run_command() {
-               // Handle --man parameter
-               if ( isset( $this->assoc_args['man'] ) ) {
-                       \WP_CLI\InternalFlags::man( $this->arguments );
-                       exit;
-               }
-
                WP_CLI::run_command( $this->arguments, $this->assoc_args );
        }
 
index 0afaea7..c66e4a9 100644 (file)
@@ -1,15 +1,20 @@
 <?php
 
-use \WP_CLI\Dispatcher\CommandContainer;
-
 class Help_Command extends WP_CLI_Command {
 
        /**
         * Get help on a certain topic.
         *
-        * @synopsis [<command>]
+        * @synopsis [<command>] [--gen]
         */
-       function __invoke( $args ) {
+       function __invoke( $args, $assoc_args ) {
+               if ( isset( $assoc_args['gen'] ) )
+                       $this->generate( $args );
+               else
+                       $this->show( $args );
+       }
+
+       private function show( $args ) {
                if ( \WP_CLI\Man\maybe_show_manpage( $args ) ) {
                        exit;
                }
@@ -26,6 +31,27 @@ class Help_Command extends WP_CLI_Command {
                        \WP_CLI::error( sprintf( "'%s' is not a registered wp command.", $args[0] ) );
                }
        }
+
+       private function generate( $args ) {
+               if ( '' === exec( 'which ronn' ) ) {
+                       WP_CLI::error( '`ronn` executable not found.' );
+               }
+
+               $arg_copy = $args;
+
+               $command = WP_CLI\Utils\find_subcommand( $args );
+
+               if ( !$command ) {
+                       WP_CLI::error( sprintf( "'%s' command not found.",
+                               implode( ' ', $arg_copy ) ) );
+               }
+
+               foreach ( WP_CLI::get_man_dirs() as $dest_dir => $src_dir ) {
+                       WP_CLI\Man\generate( $src_dir, $dest_dir, $command );
+               }
+
+               exit;
+       }
 }
 
 WP_CLI::add_command( 'help', 'Help_Command' );