diff --git a/lib/Cake/Console/ConsoleOptionParser.php b/lib/Cake/Console/ConsoleOptionParser.php index 8960e758961..86c4369c9bb 100644 --- a/lib/Cake/Console/ConsoleOptionParser.php +++ b/lib/Cake/Console/ConsoleOptionParser.php @@ -410,6 +410,17 @@ public function addSubcommand($name, $options = array()) { return $this; } +/** + * Remove an subcommand from the option parser. + * + * @param string $name The subcommand name to remove. + * @return ConsoleOptionParser this + */ + public function removeSubcommand($name) { + unset($this->_subcommands[$name]); + return $this; + } + /** * Add multiple subcommands at once. * diff --git a/lib/Cake/Test/Case/Console/ConsoleOptionParserTest.php b/lib/Cake/Test/Case/Console/ConsoleOptionParserTest.php index eabfbdd1cb5..f349922c3fe 100644 --- a/lib/Cake/Test/Case/Console/ConsoleOptionParserTest.php +++ b/lib/Cake/Test/Case/Console/ConsoleOptionParserTest.php @@ -476,6 +476,21 @@ public function testAddSubcommandObject() { $this->assertEquals('test', $result['test']->name()); } +/** + * test removeSubcommand with an object. + * + * @return void + */ + public function testRemoveSubcommand() { + $parser = new ConsoleOptionParser('test', false); + $parser->addSubcommand(new ConsoleInputSubcommand('test')); + $result = $parser->subcommands(); + $this->assertEquals(1, count($result)); + $parser->removeSubcommand('test'); + $result = $parser->subcommands(); + $this->assertEquals(0, count($result), 'Remove a subcommand does not work'); + } + /** * test adding multiple subcommands *