diff --git a/features/command.feature b/features/command.feature index 59015ad572..781ebf6fb6 100644 --- a/features/command.feature +++ b/features/command.feature @@ -490,3 +490,24 @@ Feature: WP-CLI Commands shop: cha cha cha burrito: """ + + Scenario: Removing a subcommand should remove it from the index + Given an empty directory + And a remove-comment.php file: + """ + remove_subcommand( 'comment' ); + """ + + When I run `wp` + Then STDOUT should contain: + """ + Manage comments. + """ + + When I run `wp --require=remove-comment.php` + Then STDOUT should not contain: + """ + Manage comments. + """ diff --git a/php/WP_CLI/Dispatcher/CompositeCommand.php b/php/WP_CLI/Dispatcher/CompositeCommand.php index a4712a592b..53862245b0 100644 --- a/php/WP_CLI/Dispatcher/CompositeCommand.php +++ b/php/WP_CLI/Dispatcher/CompositeCommand.php @@ -58,6 +58,19 @@ public function add_subcommand( $name, $command ) { $this->subcommands[ $name ] = $command; } + /** + * Remove a named subcommand from this composite command's set of contained + * subcommands + * + * @param string $name Represents how subcommand should be invoked + */ + public function remove_subcommand( $name ) { + if ( isset( $this->subcommands[ $name ] ) ) { + unset( $this->subcommands[ $name ] ); + } + } + + /** * Composite commands always contain subcommands. * diff --git a/php/WP_CLI/Dispatcher/RootCommand.php b/php/WP_CLI/Dispatcher/RootCommand.php index fb730da07e..0b720aea0c 100644 --- a/php/WP_CLI/Dispatcher/RootCommand.php +++ b/php/WP_CLI/Dispatcher/RootCommand.php @@ -53,8 +53,6 @@ public function find_subcommand( &$args ) { * @return array */ public function get_subcommands() { - Utils\load_all_commands(); - return parent::get_subcommands(); } } diff --git a/php/WP_CLI/Runner.php b/php/WP_CLI/Runner.php index 43bde527a2..ee11655a99 100644 --- a/php/WP_CLI/Runner.php +++ b/php/WP_CLI/Runner.php @@ -626,7 +626,7 @@ public function start() { // Load bundled commands early, so that they're forced to use the same // APIs as non-bundled commands. - Utils\load_command( $this->arguments[0] ); + Utils\load_all_commands(); $skip_packages = \WP_CLI::get_runner()->config['skip-packages']; if ( true === $skip_packages ) {