Example #1
0
 /**
  * {@inheritdoc}
  */
 protected function describeInputArgument(InputArgument $argument, array $options = array())
 {
     if (null !== $argument->getDefault() && (!is_array($argument->getDefault()) || count($argument->getDefault()))) {
         $default = sprintf('<comment> (default: %s)</comment>', $this->formatDefaultValue($argument->getDefault()));
     } else {
         $default = '';
     }
     $nameWidth = isset($options['name_width']) ? $options['name_width'] : strlen($argument->getName());
     $this->writeText(sprintf(" <info>%-{$nameWidth}s</info> %s%s", $argument->getName(), str_replace("\n", "\n" . str_repeat(' ', $nameWidth + 2), $argument->getDescription()), $default), $options);
 }
Example #2
0
 /**
  * @param InputArgument $argument
  *
  * @return \DOMDocument
  */
 private function getInputArgumentDocument(InputArgument $argument)
 {
     $dom = new \DOMDocument('1.0', 'UTF-8');
     $dom->appendChild($objectXML = $dom->createElement('argument'));
     $objectXML->setAttribute('name', $argument->getName());
     $objectXML->setAttribute('is_required', $argument->isRequired() ? 1 : 0);
     $objectXML->setAttribute('is_array', $argument->isArray() ? 1 : 0);
     $objectXML->appendChild($descriptionXML = $dom->createElement('description'));
     $descriptionXML->appendChild($dom->createTextNode($argument->getDescription()));
     $objectXML->appendChild($defaultsXML = $dom->createElement('defaults'));
     $defaults = is_array($argument->getDefault()) ? $argument->getDefault() : (is_bool($argument->getDefault()) ? array(var_export($argument->getDefault(), true)) : ($argument->getDefault() ? array($argument->getDefault()) : array()));
     foreach ($defaults as $default) {
         $defaultsXML->appendChild($defaultXML = $dom->createElement('default'));
         $defaultXML->appendChild($dom->createTextNode($default));
     }
     return $dom;
 }
Example #3
0
 /**
  * Adds an InputArgument object.
  *
  * @param InputArgument $argument An InputArgument object
  *
  * @throws \LogicException When incorrect argument is given
  *
  * @api
  */
 public function addArgument(InputArgument $argument)
 {
     if (isset($this->arguments[$argument->getName()])) {
         throw new \LogicException(sprintf('An argument with name "%s" already exists.', $argument->getName()));
     }
     if ($this->hasAnArrayArgument) {
         throw new \LogicException('Cannot add an argument after an array argument.');
     }
     if ($argument->isRequired() && $this->hasOptional) {
         throw new \LogicException('Cannot add a required argument after an optional one.');
     }
     if ($argument->isArray()) {
         $this->hasAnArrayArgument = true;
     }
     if ($argument->isRequired()) {
         ++$this->requiredCount;
     } else {
         $this->hasOptional = true;
     }
     $this->arguments[$argument->getName()] = $argument;
 }
Example #4
0
 /**
  * @param InputArgument $argument
  *
  * @return array
  */
 private function getInputArgumentData(InputArgument $argument)
 {
     return array('name' => $argument->getName(), 'is_required' => $argument->isRequired(), 'is_array' => $argument->isArray(), 'description' => $argument->getDescription(), 'default' => $argument->getDefault());
 }
Example #5
0
 /**
  * @expectedException        \LogicException
  * @expectedExceptionMessage A default value for an array argument must be an array.
  */
 public function testSetDefaultWithArrayArgument()
 {
     $argument = new InputArgument('foo', InputArgument::IS_ARRAY);
     $argument->setDefault('default');
 }
Example #6
0
 /**
  * {@inheritdoc}
  */
 protected function describeInputArgument(InputArgument $argument, array $options = array())
 {
     $this->write('**' . $argument->getName() . ':**' . "\n\n" . '* Name: ' . ($argument->getName() ?: '<none>') . "\n" . '* Is required: ' . ($argument->isRequired() ? 'yes' : 'no') . "\n" . '* Is array: ' . ($argument->isArray() ? 'yes' : 'no') . "\n" . '* Description: ' . ($argument->getDescription() ?: '<none>') . "\n" . '* Default: `' . str_replace("\n", '', var_export($argument->getDefault(), true)) . '`');
 }