Skip to content
This repository was archived by the owner on Jun 18, 2022. It is now read-only.

Commit 228e8c1

Browse files
Merge pull request wp-cli#79 from rantonmattei/2015-02-26--Default-option-value
Fix the static variable in the Lexer + fix option populating to default ...
2 parents bfe6d35 + a964211 commit 228e8c1

3 files changed

Lines changed: 15 additions & 10 deletions

File tree

lib/cli/Arguments.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,6 @@ public function parse() {
406406
if ($this->_strict && !empty($this->_invalid)) {
407407
throw new InvalidArguments($this->_invalid);
408408
}
409-
Lexer::$allowRewind = true;
410409
}
411410

412411
private function _warn($message) {
@@ -438,9 +437,16 @@ private function _parseOption($option) {
438437

439438
// Peak ahead to make sure we get a value.
440439
if ($this->_lexer->end() || !$this->_lexer->peek->isValue) {
441-
// Oops! Got no value, throw a warning and continue.
442-
$this->_warn('no value given for ' . $option->raw);
443-
$this[$option->key] = null;
440+
$optionSettings = $this->getOption($option->key);
441+
442+
if (empty($optionSettings['default'])) {
443+
// Oops! Got no value and no default , throw a warning and continue.
444+
$this->_warn('no value given for ' . $option->raw);
445+
$this[$option->key] = null;
446+
} else {
447+
// No value and we have a default, so we set to the default
448+
$this[$option->key] = $optionSettings['default'];
449+
}
444450
return true;
445451
}
446452

lib/cli/arguments/Lexer.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ class Lexer extends Memoize implements \Iterator {
1818
private $_items = array();
1919
private $_index = 0;
2020
private $_length = 0;
21-
22-
public static $allowRewind = true;
21+
private $_first = true;
2322

2423
/**
2524
* @param array $items A list of strings to process as tokens.
@@ -71,9 +70,9 @@ public function key() {
7170
*/
7271
public function rewind() {
7372
$this->_shift();
74-
if (self::$allowRewind) {
73+
if ($this->_first) {
7574
$this->_index = 0;
76-
self::$allowRewind = false;
75+
$this->_first = false;
7776
}
7877
}
7978

tests/test-arguments.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,12 +254,12 @@ public function testParseWithMissingOptions($cliParams, $expectedValues)
254254
}
255255

256256
/**
257-
* @todo implement once the "default" value issue has been fixed
257+
* @param array $args arguments as they appear in the cli
258+
* @param array $expectedValues expected values after parsing
258259
* @dataProvider settingsWithMissingOptionsWithDefault
259260
*/
260261
public function testParseWithMissingOptionsWithDefault($cliParams, $expectedValues)
261262
{
262-
$this->markTestSkipped('Will fail cause default value is not populated. Issue #30 is still open.');
263263
$this->_testParse($cliParams, $expectedValues);
264264
}
265265
}

0 commit comments

Comments
 (0)