From 2c2c9a38d2317deb6c6a3ef92b7e2369f923f5f0 Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 7 Oct 2010 23:08:32 -0400 Subject: [PATCH] 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. --- cake/console/console_option_parser.php | 12 ++++++------ .../cases/console/console_option_parser.test.php | 14 ++++++++++++++ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/cake/console/console_option_parser.php b/cake/console/console_option_parser.php index d312607c8..62e8abb67 100644 --- a/cake/console/console_option_parser.php +++ b/cake/console/console_option_parser.php @@ -94,11 +94,7 @@ class ConsoleOptionParser { * ### 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 @@ class ConsoleOptionParser { 'shortcut' => null, 'required' => false, 'description' => '', - 'type' => null, 'default' => true ); $options = array_merge($defaults, $params); @@ -150,6 +145,10 @@ class ConsoleOptionParser { */ 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 @@ class ConsoleOptionParser { /** * Find the next token in the argv set. * + * @param string * @return next token or '' */ protected function _nextToken() { diff --git a/cake/tests/cases/console/console_option_parser.test.php b/cake/tests/cases/console/console_option_parser.test.php index 23c7a546c..bf5a7afac 100644 --- a/cake/tests/cases/console/console_option_parser.test.php +++ b/cake/tests/cases/console/console_option_parser.test.php @@ -73,6 +73,20 @@ class ConsoleOptionParserTest extends CakeTestCase { $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. *