/** * @ignore */ private function parse($args) { // $found must be true or the rest string $optmatched = array_shift($args); $found = $this->isMe($optmatched); switch ($this->type) { case 'bool': if ($found !== true) { $val = Helper::trimOptValue($found); if (Helper::isTrue($val)) { $this->setValue(true, true, true); } elseif (Helper::isFalse($val)) { $this->setValue(false, true, true); } else { $this->setValue(true, true, true); $this->command->_addWarning("Unknown bool value: {$val} for option -{$this->name}, regarded as true."); } return $found; } else { if (!empty($args)) { $this->setValue(Helper::isTrue($args[0]), true, true); } else { $this->setValue(true, true, true); } } break; case 'flag': if ($found !== true) { // will never happen, cuz -b1 is not -b for flag $this->command->_addWarning("Part of the argument matched flag option -{$this->name}, use a different option name."); } else { if (!empty($args)) { // never happens $this->command->_addWarning("Flag option {$optmatched} should not be assigned value, regarded as true."); } else { $this->setValue(true, true, true); } } break; case 'array': if ($found !== true) { $this->setValue(Helper::trimOptValue($found), false); } $this->setValue($args, false); break; case 'incr': if (strlen($optmatched) >= 2 and $optmatched[0] == '-' and $optmatched[1] == '-') { // long if ($found !== true) { $this->setValue(Helper::trimOptValue($found), true, true); } else { if (empty($args) and is_null($this->value)) { $this->command->_addWarning("No value set for option {$optmatched}"); } else { $this->setValue($args[0], true, true); } } } else { // short options $val = (strlen($optmatched) - 1) / (strlen($this->matched) - 1); $this->setValue($val); } break; default: if ($found !== true) { $this->setValue(Helper::trimOptValue($found), true, true); } else { if (empty($args) and is_null($this->value)) { $this->command->_addWarning("No value set for option {$optmatched}"); } else { $this->setValue($args[0], true, true); } } break; } }