Example #1
0
 /**
  * {@inheritdoc}
  */
 protected function describeInputOption(InputOption $option, array $options = array())
 {
     if ($option->acceptValue() && null !== $option->getDefault() && (!is_array($option->getDefault()) || count($option->getDefault()))) {
         $default = sprintf('<comment> (default: %s)</comment>', $this->formatDefaultValue($option->getDefault()));
     } else {
         $default = '';
     }
     $nameWidth = isset($options['name_width']) ? $options['name_width'] : strlen($option->getName());
     $nameWithShortcutWidth = $nameWidth - strlen($option->getName()) - 2;
     $this->writeText(sprintf(" <info>%s</info> %-{$nameWithShortcutWidth}s%s%s%s", '--' . $option->getName(), $option->getShortcut() ? sprintf('(-%s) ', $option->getShortcut()) : '', str_replace("\n", "\n" . str_repeat(' ', $nameWidth + 2), $option->getDescription()), $default, $option->isArray() ? '<comment> (multiple values allowed)</comment>' : ''), $options);
 }
Example #2
0
 /**
  * @param InputOption $option
  *
  * @return \DOMDocument
  */
 private function getInputOptionDocument(InputOption $option)
 {
     $dom = new \DOMDocument('1.0', 'UTF-8');
     $dom->appendChild($objectXML = $dom->createElement('option'));
     $objectXML->setAttribute('name', '--' . $option->getName());
     $pos = strpos($option->getShortcut(), '|');
     if (false !== $pos) {
         $objectXML->setAttribute('shortcut', '-' . substr($option->getShortcut(), 0, $pos));
         $objectXML->setAttribute('shortcuts', '-' . implode('|-', explode('|', $option->getShortcut())));
     } else {
         $objectXML->setAttribute('shortcut', $option->getShortcut() ? '-' . $option->getShortcut() : '');
     }
     $objectXML->setAttribute('accept_value', $option->acceptValue() ? 1 : 0);
     $objectXML->setAttribute('is_value_required', $option->isValueRequired() ? 1 : 0);
     $objectXML->setAttribute('is_multiple', $option->isArray() ? 1 : 0);
     $objectXML->appendChild($descriptionXML = $dom->createElement('description'));
     $descriptionXML->appendChild($dom->createTextNode($option->getDescription()));
     if ($option->acceptValue()) {
         $defaults = is_array($option->getDefault()) ? $option->getDefault() : (is_bool($option->getDefault()) ? array(var_export($option->getDefault(), true)) : ($option->getDefault() ? array($option->getDefault()) : array()));
         $objectXML->appendChild($defaultsXML = $dom->createElement('defaults'));
         if (!empty($defaults)) {
             foreach ($defaults as $default) {
                 $defaultsXML->appendChild($defaultXML = $dom->createElement('default'));
                 $defaultXML->appendChild($dom->createTextNode($default));
             }
         }
     }
     return $dom;
 }
Example #3
0
 /**
  * @param InputOption $option
  *
  * @return array
  */
 private function getInputOptionData(InputOption $option)
 {
     return array('name' => '--' . $option->getName(), 'shortcut' => $option->getShortcut() ? '-' . implode('|-', explode('|', $option->getShortcut())) : '', 'accept_value' => $option->acceptValue(), 'is_value_required' => $option->isValueRequired(), 'is_multiple' => $option->isArray(), 'description' => $option->getDescription(), 'default' => $option->getDefault());
 }
Example #4
0
 public function testSetDefault()
 {
     $option = new InputOption('foo', null, InputOption::VALUE_REQUIRED, '', 'default');
     $option->setDefault(null);
     $this->assertNull($option->getDefault(), '->setDefault() can reset the default value by passing null');
     $option->setDefault('another');
     $this->assertEquals('another', $option->getDefault(), '->setDefault() changes the default value');
     $option = new InputOption('foo', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY);
     $option->setDefault(array(1, 2));
     $this->assertEquals(array(1, 2), $option->getDefault(), '->setDefault() changes the default value');
 }
Example #5
0
 /**
  * {@inheritdoc}
  */
 protected function describeInputOption(InputOption $option, array $options = array())
 {
     $this->write('**' . $option->getName() . ':**' . "\n\n" . '* Name: `--' . $option->getName() . '`' . "\n" . '* Shortcut: ' . ($option->getShortcut() ? '`-' . implode('|-', explode('|', $option->getShortcut())) . '`' : '<none>') . "\n" . '* Accept value: ' . ($option->acceptValue() ? 'yes' : 'no') . "\n" . '* Is value required: ' . ($option->isValueRequired() ? 'yes' : 'no') . "\n" . '* Is multiple: ' . ($option->isArray() ? 'yes' : 'no') . "\n" . '* Description: ' . ($option->getDescription() ?: '<none>') . "\n" . '* Default: `' . str_replace("\n", '', var_export($option->getDefault(), true)) . '`');
 }