Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions features/command.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
<?php
$command = WP_CLI::get_root_command();
$command->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.
"""
13 changes: 13 additions & 0 deletions php/WP_CLI/Dispatcher/CompositeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
2 changes: 0 additions & 2 deletions php/WP_CLI/Dispatcher/RootCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ public function find_subcommand( &$args ) {
* @return array
*/
public function get_subcommands() {
Utils\load_all_commands();

return parent::get_subcommands();
}
}
Expand Down
2 changes: 1 addition & 1 deletion php/WP_CLI/Runner.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down