Example #1
0
 /**
  * 添加一个option
  * 
  * @param string $name
  * @param string $value
  * @throws RuntimeException
  */
 protected function addNewOption($name, $value)
 {
     $option = $this->definition->getOption($name);
     if (is_null($value)) {
         if ($option->isValueRequired()) {
             $value = $this->getNextToken();
             if (!empty($value)) {
                 array_shift($this->tokens);
             } else {
                 throw new RuntimeException(sprintf('The "%s" option requires a value.', $option->isShort() ? "-{$name}" : "--{$name}"));
             }
         } elseif ($option->isValueOptional()) {
             $value = $option->getDefault();
         } elseif ($option->isValueNone()) {
             $value = true;
         }
     } else {
         if ($option->isValueNone()) {
             throw new RuntimeException(sprintf('The "%s" option does not accept a value.', $option->isShort() ? "-{$name}" : "--{$name}"));
         }
     }
     $this->options[$name] = $value;
 }