Skip to content
Permalink
Browse files

Removing required, and type from option flag as they didn't really ma…

…ke sense to include at this point. Adding support for --foo=bar type parameters.
  • Loading branch information...
markstory committed Oct 8, 2010
1 parent 7b1b835 commit 2c2c9a38d2317deb6c6a3ef92b7e2369f923f5f0
Showing with 20 additions and 6 deletions.
  1. +6 −6 cake/console/console_option_parser.php
  2. +14 −0 cake/tests/cases/console/console_option_parser.test.php
@@ -94,11 +94,7 @@ public function epilog($text = null) {
* ### Params
*
* - `shortcut` - The single letter variant for this option, leave undefined for none.
* - `required` - Set to true to force this option to be required. An exception will be thrown
* when this option is not present.
* - `description` - Description for this option.
* - `type` - Require a certain type. Available types are `int` and `string`. If the options
* value is the wrong type an exception will be raised. Leave undefined to accept anything.
* - `description` - Description for this option. Used when generating help for the option.
* - `default` - The default value for this option. If not defined the default will be true.
*
* @param string $name The long name you want to the value to be parsed out as when options are parsed.
@@ -111,7 +107,6 @@ public function addOption($name, $params = array()) {
'shortcut' => null,
'required' => false,
'description' => '',
'type' => null,
'default' => true
);
$options = array_merge($defaults, $params);
@@ -150,6 +145,10 @@ public function parse($argv) {
*/
protected function _parseLongOption($option, $params) {
$name = substr($option, 2);
if (strpos($name, '=') !== false) {
list($name, $value) = explode('=', $name, 2);
array_unshift($this->_tokens, $value);
}
return $this->_parseOptionName($name, $params);
}
@@ -188,6 +187,7 @@ protected function _parseOptionName($name, $params) {
/**
* Find the next token in the argv set.
*
* @param string
* @return next token or ''
*/
protected function _nextToken() {
@@ -73,6 +73,20 @@ function testAddOptionLong() {
$this->assertEqual(array('test' => 'value'), $result[0], 'Long parameter did not parse out');
}
/**
* test adding an option and using the long value for parsing.
*
* @return void
*/
function testAddOptionLongEquals() {
$parser = new ConsoleOptionParser();
$parser->addOption('test', array(
'shortcut' => 't'
));
$result = $parser->parse(array('--test=value'));
$this->assertEqual(array('test' => 'value'), $result[0], 'Long parameter did not parse out');
}
/**
* test adding an option and using the default.
*

0 comments on commit 2c2c9a3

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