diff --git a/lib/cli/Arguments.php b/lib/cli/Arguments.php index 59e2d61..0806dee 100644 --- a/lib/cli/Arguments.php +++ b/lib/cli/Arguments.php @@ -406,7 +406,6 @@ public function parse() { if ($this->_strict && !empty($this->_invalid)) { throw new InvalidArguments($this->_invalid); } - Lexer::$allowRewind = true; } private function _warn($message) { @@ -438,9 +437,16 @@ private function _parseOption($option) { // Peak ahead to make sure we get a value. if ($this->_lexer->end() || !$this->_lexer->peek->isValue) { - // Oops! Got no value, throw a warning and continue. - $this->_warn('no value given for ' . $option->raw); - $this[$option->key] = null; + $optionSettings = $this->getOption($option->key); + + if (empty($optionSettings['default'])) { + // Oops! Got no value and no default , throw a warning and continue. + $this->_warn('no value given for ' . $option->raw); + $this[$option->key] = null; + } else { + // No value and we have a default, so we set to the default + $this[$option->key] = $optionSettings['default']; + } return true; } diff --git a/lib/cli/arguments/Lexer.php b/lib/cli/arguments/Lexer.php index e1f714b..f6012ef 100644 --- a/lib/cli/arguments/Lexer.php +++ b/lib/cli/arguments/Lexer.php @@ -18,8 +18,7 @@ class Lexer extends Memoize implements \Iterator { private $_items = array(); private $_index = 0; private $_length = 0; - - public static $allowRewind = true; + private $_first = true; /** * @param array $items A list of strings to process as tokens. @@ -71,9 +70,9 @@ public function key() { */ public function rewind() { $this->_shift(); - if (self::$allowRewind) { + if ($this->_first) { $this->_index = 0; - self::$allowRewind = false; + $this->_first = false; } } diff --git a/tests/test-arguments.php b/tests/test-arguments.php index 748696e..c92d3fa 100644 --- a/tests/test-arguments.php +++ b/tests/test-arguments.php @@ -254,12 +254,12 @@ public function testParseWithMissingOptions($cliParams, $expectedValues) } /** - * @todo implement once the "default" value issue has been fixed + * @param array $args arguments as they appear in the cli + * @param array $expectedValues expected values after parsing * @dataProvider settingsWithMissingOptionsWithDefault */ public function testParseWithMissingOptionsWithDefault($cliParams, $expectedValues) { - $this->markTestSkipped('Will fail cause default value is not populated. Issue #30 is still open.'); $this->_testParse($cliParams, $expectedValues); } }