isRequired() 공개 메소드

public isRequired ( )
예제 #1
0
 /**
  * consume option value from current argument or from the next argument
  *
  * @return boolean next token consumed?
  */
 protected function consumeOptionToken(Option $spec, $arg, $next, &$success = false)
 {
     // Check options doesn't require next token before
     // all options that require values.
     if ($spec->isFlag()) {
         if ($spec->isIncremental()) {
             $spec->increaseValue();
         } else {
             $spec->setValue(true);
         }
         return 0;
     } else {
         if ($spec->isRequired()) {
             if ($next && !$next->isEmpty() && !$next->anyOfOptions($this->specs)) {
                 $spec->setValue($next->arg);
                 return 1;
             } else {
                 throw new RequireValueException("Option '{$arg->getOptionName()}' requires a value.");
             }
         } else {
             if ($spec->isMultiple()) {
                 if ($next && !$next->isEmpty() && !$next->anyOfOptions($this->specs)) {
                     $this->pushOptionValue($spec, $arg, $next);
                     return 1;
                 }
             } else {
                 if ($spec->isOptional() && $next && !$next->isEmpty() && !$next->anyOfOptions($this->specs)) {
                     $spec->setValue($next->arg);
                     return 1;
                 }
             }
         }
     }
     return 0;
 }
예제 #2
0
 public function renderOptionValueHint(Option $opt, $assign = true)
 {
     $n = 'value';
     if ($opt->valueName) {
         $n = $opt->valueName;
     } elseif ($opt->isa) {
         $n = $opt->isa;
     }
     if ($opt->isRequired()) {
         return sprintf('%s<%s>', $assign ? '=' : ' ', $this->formatter->format($n, 'underline'));
     } elseif ($opt->isOptional()) {
         return sprintf('%s[<%s>]', $assign ? '=' : ' ', $this->formatter->format($n, 'underline'));
     }
     return '';
 }