Add removeSubcommand in ConsoleOptionParser

This commit is contained in:
Denys Kyselov 2014-07-21 01:02:10 +03:00 committed by mark_story
parent 183c1e1276
commit 79dc624062
2 changed files with 26 additions and 0 deletions

View file

@ -410,6 +410,17 @@ class ConsoleOptionParser {
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.
*

View file

@ -476,6 +476,21 @@ class ConsoleOptionParserTest extends CakeTestCase {
$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
*