namespace WP_CLI\Dispatcher;
+use \WP_CLI\Utils;
+
class RootCommand extends AbstractCommandContainer implements Documentable {
function get_name() {
if ( isset( $aliases[ $command ] ) )
$command = $aliases[ $command ];
- return $this->load_command( $command );
- }
-
- function get_subcommands() {
- $this->load_all_commands();
-
- return parent::get_subcommands();
- }
-
- protected function load_all_commands() {
- $cmd_dir = WP_CLI_ROOT . "commands";
+ Utils\load_command( $command );
- $iterator = new \DirectoryIterator( $cmd_dir );
-
- foreach ( $iterator as $filename ) {
- if ( '.php' != substr( $filename, -4 ) )
- continue;
-
- $command = substr( $filename, 0, -4 );
-
- if ( isset( $this->subcommands[ $command ] ) )
- continue;
-
- include "$cmd_dir/$filename";
- }
- }
-
- protected static function get_command_file( $command ) {
- $path = WP_CLI_ROOT . "/commands/$command.php";
-
- if ( !is_readable( $path ) ) {
+ if ( !isset( $this->subcommands[ $command ] ) ) {
return false;
}
- return $path;
+ return $this->subcommands[ $command ];
}
- protected function load_command( $command ) {
- if ( !isset( $this->subcommands[ $command ] ) ) {
- if ( $path = self::get_command_file( $command ) )
- include $path;
- }
-
- if ( !isset( $this->subcommands[ $command ] ) ) {
- return false;
- }
+ function get_subcommands() {
+ Utils\load_all_commands();
- return $this->subcommands[ $command ];
+ return parent::get_subcommands();
}
}
include WP_CLI_ROOT . 'Spyc.php';
}
+function load_command( $name ) {
+ $path = WP_CLI_ROOT . "/commands/$name.php";
+
+ if ( is_readable( $path ) ) {
+ include_once $path;
+ }
+}
+
+function load_all_commands() {
+ $cmd_dir = WP_CLI_ROOT . "commands";
+
+ $iterator = new \DirectoryIterator( $cmd_dir );
+
+ foreach ( $iterator as $filename ) {
+ if ( '.php' != substr( $filename, -4 ) )
+ continue;
+
+ include_once "$cmd_dir/$filename";
+ }
+}
+
function get_config_spec() {
$spec = include __DIR__ . '/config-spec.php';