Ejemplo n.º 1
0
 /**
  * Create usage instructions for a field
  *
  * @param sndsgd\Field $field
  * @return string
  */
 private function createFieldUsage(Field $field)
 {
     $name = $field->getName();
     $opts = array_merge(["--{$name}"], $field->getAliases());
     $isBoolean = $field instanceof BooleanField;
     $hint = $field->getData('short-hint', $name);
     array_walk($opts, function (&$v) use($isBoolean, $hint) {
         $isName = substr($v, 0, 2) === '--';
         if ($isName) {
             if (!$isBoolean) {
                 $v .= '=';
             }
         } else {
             if (!$isName) {
                 $v = "-{$v} ";
             }
         }
         if (!$isBoolean) {
             $v .= "<{$hint}>";
         }
         $v = trim($v);
     });
     $opts = implode('|', $opts);
     $isRequired = $field->hasRule('sndsgd\\field\\rule\\Required');
     if (!$isRequired) {
         $opts = "[{$opts}]";
     }
     return $opts;
 }