OSDN Git Service

convert InternalFlags class to Sys_Command
authorscribu <mail@scribu.net>
Sun, 2 Jun 2013 20:08:50 +0000 (23:08 +0300)
committerscribu <mail@scribu.net>
Sun, 2 Jun 2013 21:50:03 +0000 (00:50 +0300)
php/WP_CLI/Dispatcher/RootCommand.php
php/WP_CLI/Runner.php
php/commands/_sys.php [moved from php/WP_CLI/InternalFlags.php with 65% similarity]

index e47721a..9fc159a 100644 (file)
@@ -26,6 +26,9 @@ class RootCommand extends AbstractCommandContainer implements Documentable {
                \WP_CLI::line( 'Available commands:' );
 
                foreach ( $this->get_subcommands() as $command ) {
+                       if ( '_sys' == $command->get_name() )
+                               continue;
+
                        \WP_CLI::line( sprintf( "    %s %s",
                                implode( ' ', get_path( $command ) ),
                                implode( '|', array_keys( get_subcommands( $command ) ) )
index 22e1a60..dcfe5ff 100644 (file)
@@ -251,6 +251,16 @@ class Runner {
                        unset( $assoc_args['json'] );
                }
 
+               // --{version|info}  ->  _sys {version|info}
+               if ( empty( $args ) ) {
+                       foreach ( array( 'version', 'info' ) as $key ) {
+                               if ( isset( $assoc_args[ $key ] ) ) {
+                                       $args = array( '_sys', $key );
+                                       break;
+                               }
+                       }
+               }
+
                return array( $args, $assoc_args );
        }
 
@@ -292,19 +302,13 @@ class Runner {
 
                $this->init_logger();
 
-               // Handle a bunch of special-purpose flags
-               if ( empty( $this->arguments ) ) {
-                       foreach ( array( 'version', 'info', 'param-dump', 'cmd-dump' ) as $key  ) {
-                               if ( isset( $this->assoc_args[ $key ] ) ) {
-                                       call_user_func( array( '\\WP_CLI\\InternalFlags',
-                                               str_replace( '-', '_', $key ) ) );
-                                       exit;
-                               }
-                       }
-               }
-
                $_SERVER['DOCUMENT_ROOT'] = realpath( $this->config['path'] );
 
+               if ( $this->cmd_starts_with( array( '_sys' ) ) ) {
+                       $this->_run_command();
+                       exit;
+               }
+
                // First try at showing man page
                if ( $this->cmd_starts_with( array( 'help' ) ) ) {
                        $this->_run_command();
@@ -367,7 +371,11 @@ class Runner {
 
                // Handle --completions parameter
                if ( isset( $this->assoc_args['completions'] ) ) {
-                       \WP_CLI\InternalFlags::completions();
+                       foreach ( WP_CLI::$root->get_subcommands() as $name => $command ) {
+                               $subcommands = Dispatcher\get_subcommands( $command );
+
+                               WP_CLI::line( $name . ' ' . implode( ' ', array_keys( $subcommands ) ) );
+                       }
                        exit;
                }
 
similarity index 65%
rename from php/WP_CLI/InternalFlags.php
rename to php/commands/_sys.php
index 1f5bf70..af2b1b7 100644 (file)
@@ -1,37 +1,11 @@
 <?php
 
-namespace WP_CLI;
-use \WP_CLI;
+use \WP_CLI\Dispatcher,
+       \WP_CLI\Utils;
 
-/**
- * Class that handles special assoc parameters
- */
-class InternalFlags {
+class Sys_Command extends WP_CLI_Command {
 
-       static function version() {
-               WP_CLI::line( 'wp-cli ' . WP_CLI_VERSION );
-       }
-
-       static function info() {
-               $php_bin = defined( 'PHP_BINARY' ) ? PHP_BINARY : getenv( 'WP_CLI_PHP_USED' );
-
-               WP_CLI::line( "PHP binary:\t" . $php_bin );
-               WP_CLI::line( "PHP version:\t" . PHP_VERSION );
-               WP_CLI::line( "php.ini used:\t" . get_cfg_var( 'cfg_file_path' ) );
-               WP_CLI::line( "wp-cli root:\t" . WP_CLI_ROOT );
-               WP_CLI::line( "wp-cli config:\t" . WP_CLI::get_config_path() );
-               WP_CLI::line( "wp-cli version:\t" . WP_CLI_VERSION );
-       }
-
-       static function param_dump() {
-               echo json_encode( Utils\get_config_spec() );
-       }
-
-       static function cmd_dump() {
-               echo json_encode( self::command_to_array( WP_CLI::$root ) );
-       }
-
-       private static function command_to_array( $command ) {
+       private function command_to_array( $command ) {
                $dump = array(
                        'name' => $command->get_name(),
                        'description' => $command->get_shortdesc(),
@@ -48,12 +22,35 @@ class InternalFlags {
                return $dump;
        }
 
-       static function completions() {
-               foreach ( WP_CLI::$root->get_subcommands() as $name => $command ) {
-                       $subcommands = Dispatcher\get_subcommands( $command );
+       function version() {
+               WP_CLI::line( 'wp-cli ' . WP_CLI_VERSION );
+       }
 
-                       WP_CLI::line( $name . ' ' . implode( ' ', array_keys( $subcommands ) ) );
-               }
+       function info() {
+               $php_bin = defined( 'PHP_BINARY' ) ? PHP_BINARY : getenv( 'WP_CLI_PHP_USED' );
+
+               WP_CLI::line( "PHP binary:\t" . $php_bin );
+               WP_CLI::line( "PHP version:\t" . PHP_VERSION );
+               WP_CLI::line( "php.ini used:\t" . get_cfg_var( 'cfg_file_path' ) );
+               WP_CLI::line( "wp-cli root:\t" . WP_CLI_ROOT );
+               WP_CLI::line( "wp-cli config:\t" . WP_CLI::get_config_path() );
+               WP_CLI::line( "wp-cli version:\t" . WP_CLI_VERSION );
+       }
+
+       /**
+        * @subcommand param-dump
+        */
+       function param_dump() {
+               echo json_encode( Utils\get_config_spec() );
+       }
+
+       /**
+        * @subcommand cmd-dump
+        */
+       function cmd_dump() {
+               echo json_encode( self::command_to_array( WP_CLI::$root ) );
        }
 }
 
+WP_CLI::add_command( '_sys', 'Sys_Command' );
+