Skip to content

Commit 28880df

Browse files
Merge pull request #98 from wp-cli/revert-97-defaults-fix
Revert "always populate parsed arguments with default values"
2 parents 6f8e13b + 4c140c2 commit 28880df

File tree

2 files changed

+3
-41
lines changed

2 files changed

+3
-41
lines changed

lib/cli/Arguments.php

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -392,8 +392,6 @@ public function parse() {
392392
$this->_parsed = array();
393393
$this->_lexer = new Lexer($this->_input);
394394

395-
$this->_applyDefaults();
396-
397395
foreach ($this->_lexer as $argument) {
398396
if ($this->_parseFlag($argument)) {
399397
continue;
@@ -410,24 +408,6 @@ public function parse() {
410408
}
411409
}
412410

413-
/**
414-
* This applies the default values, if any, of all of the
415-
* flags and options, so that if there is a default value
416-
* it will be available.
417-
*/
418-
private function _applyDefaults() {
419-
foreach($this->_flags as $flag => $settings) {
420-
$this[$flag] = $settings['default'];
421-
}
422-
423-
foreach($this->_options as $option => $settings) {
424-
// If the default is 0 we should still let it be set.
425-
if (!empty($settings['default']) || $settings['default'] === 0) {
426-
$this[$option] = $settings['default'];
427-
}
428-
}
429-
}
430-
431411
private function _warn($message) {
432412
trigger_error('[' . __CLASS__ .'] ' . $message, E_USER_WARNING);
433413
}
@@ -459,7 +439,7 @@ private function _parseOption($option) {
459439
if ($this->_lexer->end() || !$this->_lexer->peek->isValue) {
460440
$optionSettings = $this->getOption($option->key);
461441

462-
if (empty($optionSettings['default']) && $optionSettings !== 0) {
442+
if (empty($optionSettings['default'])) {
463443
// Oops! Got no value and no default , throw a warning and continue.
464444
$this->_warn('no value given for ' . $option->raw);
465445
$this[$option->key] = null;
@@ -486,3 +466,4 @@ private function _parseOption($option) {
486466
return true;
487467
}
488468
}
469+

tests/test-arguments.php

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ public function testAddOptions()
146146
}
147147

148148
/**
149-
* Data provider with valid args and options
149+
* Data provider with valid fags and options
150150
*
151151
* @return array set of args and expected parsed values
152152
*/
@@ -206,16 +206,6 @@ public function settingsWithMissingOptionsWithDefault()
206206
);
207207
}
208208

209-
public function settingsWithNoOptionsWithDefault()
210-
{
211-
return array(
212-
array(
213-
array(),
214-
array('flag1' => false, 'flag2' => false, 'option2' => 'some default value')
215-
)
216-
);
217-
}
218-
219209
/**
220210
* Generic private testParse method.
221211
*
@@ -272,13 +262,4 @@ public function testParseWithMissingOptionsWithDefault($cliParams, $expectedValu
272262
{
273263
$this->_testParse($cliParams, $expectedValues);
274264
}
275-
276-
/**
277-
* @param array $args arguments as they appear in the cli
278-
* @param array $expectedValues expected values after parsing
279-
* @dataProvider settingsWithNoOptionsWithDefault
280-
*/
281-
public function testParseWithNoOptionsWithDefault($cliParams, $expectedValues) {
282-
$this->_testParse($cliParams, $expectedValues);
283-
}
284265
}

0 commit comments

Comments
 (0)