Skip to content

Commit

Permalink
Add removeSubcommand in ConsoleOptionParser
Browse files Browse the repository at this point in the history
  • Loading branch information
TamiasSibiricus authored and markstory committed Jul 22, 2014
1 parent 183c1e1 commit 79dc624
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/Cake/Console/ConsoleOptionParser.php
Expand Up @@ -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.
*
Expand Down
15 changes: 15 additions & 0 deletions lib/Cake/Test/Case/Console/ConsoleOptionParserTest.php
Expand Up @@ -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
*
Expand Down

0 comments on commit 79dc624

Please sign in to comment.