OSDN Git Service

move find_command_to_run() method to WP_CLI\Runner
authorscribu <mail@scribu.net>
Tue, 23 Jul 2013 19:57:52 +0000 (22:57 +0300)
committerscribu <mail@scribu.net>
Tue, 23 Jul 2013 20:19:25 +0000 (23:19 +0300)
the WP_CLI class should be a simple facade, with only public methods

php/WP_CLI/Runner.php
php/class-wp-cli.php

index 9a08694..8af6b2a 100644 (file)
@@ -144,8 +144,47 @@ class Runner {
                return $prefix == array_slice( $this->arguments, 0, count( $prefix ) );
        }
 
+       private function find_command_to_run( $args ) {
+               $command = \WP_CLI::get_root_command();
+
+               $cmd_path = array();
+
+               $disabled_commands = $this->config['disabled_commands'];
+
+               while ( !empty( $args ) && $command->has_subcommands() ) {
+                       $cmd_path[] = $args[0];
+                       $full_name = implode( ' ', $cmd_path );
+
+                       $subcommand = $command->find_subcommand( $args );
+
+                       if ( !$subcommand ) {
+                               \WP_CLI::error( sprintf(
+                                       "'%s' is not a registered wp command. See 'wp help'.",
+                                       $full_name
+                               ) );
+                       }
+
+                       if ( in_array( $full_name, $disabled_commands ) ) {
+                               \WP_CLI::error( sprintf(
+                                       "The '%s' command has been disabled from the config file.",
+                                       $full_name
+                               ) );
+                       }
+
+                       $command = $subcommand;
+               }
+
+               return array( $command, $args );
+       }
+
+       public function run_command( $args, $assoc_args = array() ) {
+               list( $command, $final_args ) = $this->find_command_to_run( $args );
+
+               $command->invoke( $final_args, $assoc_args );
+       }
+
        private function _run_command() {
-               WP_CLI::run_command( $this->arguments, $this->assoc_args );
+               $this->run_command( $this->arguments, $this->assoc_args );
        }
 
        /**
index 7d2c9df..1408f97 100644 (file)
@@ -266,49 +266,14 @@ class WP_CLI {
                return self::get_runner()->config[ $key ];
        }
 
-       private static function find_command_to_run( $args ) {
-               $command = self::get_root_command();
-
-               $cmd_path = array();
-
-               $disabled_commands = self::get_config('disabled_commands');
-
-               while ( !empty( $args ) && $command->has_subcommands() ) {
-                       $cmd_path[] = $args[0];
-                       $full_name = implode( ' ', $cmd_path );
-
-                       $subcommand = $command->find_subcommand( $args );
-
-                       if ( !$subcommand ) {
-                               self::error( sprintf(
-                                       "'%s' is not a registered wp command. See 'wp help'.",
-                                       $full_name
-                               ) );
-                       }
-
-                       if ( in_array( $full_name, $disabled_commands ) ) {
-                               self::error( sprintf(
-                                       "The '%s' command has been disabled from the config file.",
-                                       $full_name
-                               ) );
-                       }
-
-                       $command = $subcommand;
-               }
-
-               return array( $command, $args );
-       }
-
        /**
         * Run a given command.
         *
         * @param array
         * @param array
         */
-       public static function run_command( $args, $assoc_args = array() ) {
-               list( $command, $final_args ) = self::find_command_to_run( $args );
-
-               $command->invoke( $final_args, $assoc_args );
+       static function run_command( $args, $assoc_args = array() ) {
+               self::get_runner()->run_command( $args, $assoc_args );
        }
 
        // back-compat