Skip to content

Commit

Permalink
Add ConsoleOptionParser::removeOption()
Browse files Browse the repository at this point in the history
When building option parsers with inheritance it is sometimes useful to
remove options that the parent class added.
  • Loading branch information
markstory committed Apr 9, 2014
1 parent 97acf5a commit 1b24fcd
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
11 changes: 11 additions & 0 deletions src/Console/ConsoleOptionParser.php
Expand Up @@ -303,6 +303,17 @@ public function addOption($name, $options = []) {
return $this;
}

/**
* Remove an option from the option parser.
*
* @param string $name The option name to remove.
* @return ConsoleOptionParser $this
*/
public function removeOption($name) {
unset($this->_options[$name]);
return $this;
}

/**
* Add a positional argument to the option parser.
*
Expand Down
16 changes: 14 additions & 2 deletions tests/TestCase/Console/ConsoleOptionParserTest.php
@@ -1,7 +1,5 @@
<?php
/**
* ConsoleOptionParserTest file
*
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
Expand Down Expand Up @@ -71,6 +69,20 @@ public function testAddOptionReturnSelf() {
$this->assertEquals($parser, $result, 'Did not return $this from addOption');
}

/**
* test removing an option
*
* @return void
*/
public function testRemoveOption() {
$parser = new ConsoleOptionParser('test', false);
$result = $parser->addOption('test')
->removeOption('test')
->removeOption('help');
$this->assertSame($parser, $result, 'Did not return $this from removeOption');
$this->assertEquals([], $result->options());
}

/**
* test adding an option and using the long value for parsing.
*
Expand Down

0 comments on commit 1b24fcd

Please sign in to comment.