Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions lib/cli/Arguments.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}

Expand Down
7 changes: 3 additions & 4 deletions lib/cli/arguments/Lexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
}
}

Expand Down
4 changes: 2 additions & 2 deletions tests/test-arguments.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}