Skip to content
Permalink
Browse files

Adding addOptions and addArguments as convience methods for adding mu…

…ltiple options/arguments.
  • Loading branch information...
markstory committed Oct 10, 2010
1 parent 72e1a96 commit ad367fed9a55c5d20675e77903a66e06adfd1333
Showing with 64 additions and 0 deletions.
  1. +30 −0 cake/console/console_option_parser.php
  2. +34 −0 cake/tests/cases/console/console_option_parser.test.php
@@ -235,6 +235,36 @@ public function addArgument($name, $params = array()) {
return $this;
}
/**
* Add multiple arugments at once. Take an array of arugment defintions.
* The keys are used as the argument names, and the values as params for the argument.
*
* @param array $args Array of arguments to add.
* @see ConsoleOptionParser::addArgument()
* @return $this
*/
public function addArguments(array $args) {
foreach ($args as $name => $params) {
$this->addArgument($name, $params);
}
return $this;
}
/**
* Add multiple options at once. Takes an array of option definitions.
* The keys are used as option names, and the values as params for the option.
*
* @param array $options Array of options to add.
* @see ConsoleOptionParser::addOption()
* @return $this
*/
public function addOptions(array $options) {
foreach ($options as $name => $params) {
$this->addOption($name, $params);
}
return $this;
}
/**
* Append a subcommand to the subcommand list.
* Subcommands are usually methods on your Shell, but can also be used to document
@@ -150,6 +150,23 @@ function testMultipleOptions() {
$this->assertEquals($expected, $result[0], 'multiple options did not parse');
}
/**
* Test adding multiple options.
*
* @return void
*/
function testAddOptions() {
$parser = new ConsoleOptionParser('something', false);
$result = $parser->addOptions(array(
'name' => array('help' => 'The name'),
'other' => array('help' => 'The other arg')
));
$this->assertEquals($parser, $result, 'addOptions is not chainable.');
$result = $parser->options();
$this->assertEquals(3, count($result), 'Not enough options');
}
/**
* test that boolean options work
*
@@ -234,6 +251,23 @@ function testPositionalArgNotEnough() {
$parser->parse(array('one'));
}
/**
* Test adding multiple arguments.
*
* @return void
*/
function testAddArguments() {
$parser = new ConsoleOptionParser();
$result = $parser->addArguments(array(
'name' => array('help' => 'The name'),
'other' => array('help' => 'The other arg')
));
$this->assertEquals($parser, $result, 'addArguments is not chainable.');
$result = $parser->arguments();
$this->assertEquals(2, count($result), 'Not enough arguments');
}
/**
* test setting a subcommand up.
*

0 comments on commit ad367fe

Please sign in to comment.
You can’t perform that action at this time.