From 10b35f3d34b8bf060f3b5267c90802e587ae9cfa Mon Sep 17 00:00:00 2001 From: scribu Date: Tue, 1 Jan 2013 18:56:53 +0200 Subject: [PATCH] replace --syn-list with --cmd-dump --- php/WP_CLI/Dispatcher/RootCommand.php | 10 +++++++++- php/WP_CLI/Dispatcher/Subcommand.php | 8 ++++++-- php/class-wp-cli.php | 37 ++++++++++++++++++++++++----------- php/dispatcher.php | 1 + 4 files changed, 42 insertions(+), 14 deletions(-) diff --git a/php/WP_CLI/Dispatcher/RootCommand.php b/php/WP_CLI/Dispatcher/RootCommand.php index 080ad4cb..0e721678 100644 --- a/php/WP_CLI/Dispatcher/RootCommand.php +++ b/php/WP_CLI/Dispatcher/RootCommand.php @@ -2,7 +2,7 @@ namespace WP_CLI\Dispatcher; -class RootCommand extends AbstractCommandContainer { +class RootCommand extends AbstractCommandContainer implements Documentable { function get_name() { return 'wp'; @@ -12,6 +12,14 @@ class RootCommand extends AbstractCommandContainer { return false; } + function get_shortdesc() { + return ''; + } + + function get_full_synopsis() { + return ''; + } + function show_usage() { \WP_CLI::line( 'Available commands:' ); diff --git a/php/WP_CLI/Dispatcher/Subcommand.php b/php/WP_CLI/Dispatcher/Subcommand.php index 0432e7a8..e725199d 100644 --- a/php/WP_CLI/Dispatcher/Subcommand.php +++ b/php/WP_CLI/Dispatcher/Subcommand.php @@ -23,11 +23,15 @@ class Subcommand implements Command, AtomicCommand, Documentable { function get_full_synopsis() { $full_name = implode( ' ', get_path( $this ) ); - $synopsis = $this->docparser->get_synopsis(); + $synopsis = $this->get_synopsis(); return "$full_name $synopsis"; } + function get_synopsis() { + return $this->docparser->get_synopsis(); + } + function invoke( $args, $assoc_args ) { $this->check_args( $args, $assoc_args ); @@ -43,7 +47,7 @@ class Subcommand implements Command, AtomicCommand, Documentable { } protected function check_args( $args, $assoc_args ) { - $synopsis = $this->docparser->get_synopsis(); + $synopsis = $this->get_synopsis(); if ( !$synopsis ) return; diff --git a/php/class-wp-cli.php b/php/class-wp-cli.php index 34848dbc..407d2555 100644 --- a/php/class-wp-cli.php +++ b/php/class-wp-cli.php @@ -261,7 +261,7 @@ class WP_CLI { self::split_special( array( 'path', 'url', 'blog', 'user', 'require', - 'quiet', 'completions', 'man', 'syn-list' + 'quiet', 'completions', 'man', 'cmd-dump' ) ); } @@ -381,16 +381,8 @@ class WP_CLI { exit; } - // Handle --syn-list parameter - if ( isset( self::$config['syn-list'] ) ) { - foreach ( self::$root->get_subcommands() as $command ) { - if ( $command instanceof Dispatcher\CommandContainer ) { - foreach ( $command->get_subcommands() as $subcommand ) - $subcommand->show_usage( '' ); - } else { - $command->show_usage( '' ); - } - } + if ( isset( self::$config['cmd-dump'] ) ) { + self::cmd_dump(); exit; } @@ -402,6 +394,29 @@ class WP_CLI { self::run_command(); } + private static function cmd_dump() { + $dump = self::command_to_array( self::$root ); + + echo json_encode( $dump['subcommands'] ); + } + + private static function command_to_array( $command ) { + $dump = array( + 'name' => $command->get_name(), + 'description' => $command->get_shortdesc(), + ); + + if ( $command instanceof Dispatcher\AtomicCommand ) { + $dump['synopsis'] = $command->get_synopsis(); + } else { + foreach ( Dispatcher\get_subcommands( $command ) as $subcommand ) { + $dump['subcommands'][] = self::command_to_array( $subcommand ); + } + } + + return $dump; + } + private static function run_command() { Utils\run_command( self::$arguments, self::$assoc_args ); } diff --git a/php/dispatcher.php b/php/dispatcher.php index 7b790767..da4e1b0f 100644 --- a/php/dispatcher.php +++ b/php/dispatcher.php @@ -31,6 +31,7 @@ interface Command { interface AtomicCommand { + function get_synopsis(); function invoke( $args, $assoc_args ); } -- 2.11.0