From c12b24d6201cc09dd4e9c22a04dbed904b6e3225 Mon Sep 17 00:00:00 2001 From: scribu Date: Mon, 20 May 2013 15:20:07 +0300 Subject: [PATCH] convert `wp --man` to `wp help --gen` --- php/WP_CLI/Dispatcher/RootCommand.php | 5 ----- php/WP_CLI/InternalFlags.php | 22 ---------------------- php/WP_CLI/Runner.php | 6 ------ php/commands/help.php | 34 ++++++++++++++++++++++++++++++---- 4 files changed, 30 insertions(+), 37 deletions(-) diff --git a/php/WP_CLI/Dispatcher/RootCommand.php b/php/WP_CLI/Dispatcher/RootCommand.php index 0da342d7..4c74f82c 100644 --- a/php/WP_CLI/Dispatcher/RootCommand.php +++ b/php/WP_CLI/Dispatcher/RootCommand.php @@ -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 ); diff --git a/php/WP_CLI/InternalFlags.php b/php/WP_CLI/InternalFlags.php index 87cabf37..1f5bf708 100644 --- a/php/WP_CLI/InternalFlags.php +++ b/php/WP_CLI/InternalFlags.php @@ -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 ); - } - } } diff --git a/php/WP_CLI/Runner.php b/php/WP_CLI/Runner.php index 106fc647..10796371 100644 --- a/php/WP_CLI/Runner.php +++ b/php/WP_CLI/Runner.php @@ -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 ); } diff --git a/php/commands/help.php b/php/commands/help.php index 0afaea74..c66e4a99 100644 --- a/php/commands/help.php +++ b/php/commands/help.php @@ -1,15 +1,20 @@ ] + * @synopsis [] [--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' ); -- 2.11.0