OSDN Git Service

replace --syn-list with --cmd-dump
authorscribu <mail@scribu.net>
Tue, 1 Jan 2013 16:56:53 +0000 (18:56 +0200)
committerscribu <mail@scribu.net>
Tue, 1 Jan 2013 20:36:44 +0000 (22:36 +0200)
php/WP_CLI/Dispatcher/RootCommand.php
php/WP_CLI/Dispatcher/Subcommand.php
php/class-wp-cli.php
php/dispatcher.php

index 080ad4c..0e72167 100644 (file)
@@ -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:' );
 
index 0432e7a..e725199 100644 (file)
@@ -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;
 
index 34848db..407d255 100644 (file)
@@ -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 );
        }
index 7b79076..da4e1b0 100644 (file)
@@ -31,6 +31,7 @@ interface Command {
 
 interface AtomicCommand {
 
+       function get_synopsis();
        function invoke( $args, $assoc_args );
 }