mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 02:56:15 +00:00
Removing required, and type from option flag as they didn't really make sense to include at this point. Adding support for --foo=bar type parameters.
This commit is contained in:
parent
7b1b835bc1
commit
2c2c9a38d2
2 changed files with 20 additions and 6 deletions
|
@ -94,11 +94,7 @@ class ConsoleOptionParser {
|
||||||
* ### Params
|
* ### Params
|
||||||
*
|
*
|
||||||
* - `shortcut` - The single letter variant for this option, leave undefined for none.
|
* - `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
|
* - `description` - Description for this option. Used when generating help for the option.
|
||||||
* 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.
|
|
||||||
* - `default` - The default value for this option. If not defined the default will be true.
|
* - `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.
|
* @param string $name The long name you want to the value to be parsed out as when options are parsed.
|
||||||
|
@ -111,7 +107,6 @@ class ConsoleOptionParser {
|
||||||
'shortcut' => null,
|
'shortcut' => null,
|
||||||
'required' => false,
|
'required' => false,
|
||||||
'description' => '',
|
'description' => '',
|
||||||
'type' => null,
|
|
||||||
'default' => true
|
'default' => true
|
||||||
);
|
);
|
||||||
$options = array_merge($defaults, $params);
|
$options = array_merge($defaults, $params);
|
||||||
|
@ -150,6 +145,10 @@ class ConsoleOptionParser {
|
||||||
*/
|
*/
|
||||||
protected function _parseLongOption($option, $params) {
|
protected function _parseLongOption($option, $params) {
|
||||||
$name = substr($option, 2);
|
$name = substr($option, 2);
|
||||||
|
if (strpos($name, '=') !== false) {
|
||||||
|
list($name, $value) = explode('=', $name, 2);
|
||||||
|
array_unshift($this->_tokens, $value);
|
||||||
|
}
|
||||||
return $this->_parseOptionName($name, $params);
|
return $this->_parseOptionName($name, $params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -188,6 +187,7 @@ class ConsoleOptionParser {
|
||||||
/**
|
/**
|
||||||
* Find the next token in the argv set.
|
* Find the next token in the argv set.
|
||||||
*
|
*
|
||||||
|
* @param string
|
||||||
* @return next token or ''
|
* @return next token or ''
|
||||||
*/
|
*/
|
||||||
protected function _nextToken() {
|
protected function _nextToken() {
|
||||||
|
|
|
@ -73,6 +73,20 @@ class ConsoleOptionParserTest extends CakeTestCase {
|
||||||
$this->assertEqual(array('test' => 'value'), $result[0], 'Long parameter did not parse out');
|
$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.
|
* test adding an option and using the default.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Reference in a new issue