/**
  * {@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);
 }
예제 #2
0
 /**
  * {@inheritdoc}
  */
 protected function describeInputOption(InputOption $option, array $options = array())
 {
     $name = '--' . $option->getName();
     if ($option->getShortcut()) {
         $name .= '|-' . implode('|-', explode('|', $option->getShortcut())) . '';
     }
     $this->write('#### `' . $name . '`' . "\n\n" . ($option->getDescription() ? preg_replace('/\\s*[\\r\\n]\\s*/', "\n", $option->getDescription()) . "\n\n" : '') . '* Accept value: ' . ($option->acceptValue() ? 'yes' : 'no') . "\n" . '* Is value required: ' . ($option->isValueRequired() ? 'yes' : 'no') . "\n" . '* Is multiple: ' . ($option->isArray() ? 'yes' : 'no') . "\n" . '* Default: `' . str_replace("\n", '', var_export($option->getDefault(), true)) . '`');
 }
예제 #3
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 = '';
     }
     $value = '';
     if ($option->acceptValue()) {
         $value = '=' . strtoupper($option->getName());
         if ($option->isValueOptional()) {
             $value = '[' . $value . ']';
         }
     }
     $totalWidth = isset($options['total_width']) ? $options['total_width'] : $this->calculateTotalWidthForOptions(array($option));
     $synopsis = sprintf('%s%s', $option->getShortcut() ? sprintf('-%s, ', $option->getShortcut()) : '    ', sprintf('--%s%s', $option->getName(), $value));
     $spacingWidth = $totalWidth - strlen($synopsis) + 2;
     $this->writeText(sprintf('  <info>%s</info>%s%s%s%s', $synopsis, str_repeat(' ', $spacingWidth), preg_replace('/\\s*[\\r\\n]\\s*/', "\n" . str_repeat(' ', $totalWidth + 17), $option->getDescription()), $default, $option->isArray() ? '<comment> (multiple values allowed)</comment>' : ''), $options);
 }
예제 #4
0
 /**
  * {@inheritdoc}
  */
 protected function describeInputOption(InputOption $option, array $options = array())
 {
     $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 $this->output($dom, $options);
 }
 /**
  * {@inheritdoc}
  */
 protected function describeInputOption(InputOption $option, array $options = [])
 {
     $this->write('* **`--' . $option->getName() . "`**");
     if ($shortcut = $option->getShortcut()) {
         $this->write(" (`-" . implode('|-', explode('|', $shortcut)) . "`)");
     }
     $notes = [];
     if ($option->isArray()) {
         $notes[] = 'multiple values allowed';
     } elseif ($option->acceptValue()) {
         $notes[] = 'expects a value';
     }
     if ($notes) {
         $this->write(' (' . implode('; ', $notes) . ')');
     }
     if ($description = $option->getDescription()) {
         $this->write("  \n  " . $description);
     }
     if ($option->acceptValue() && $option->getDefault()) {
         $default = var_export($option->getDefault(), true);
         $this->write("  \n  Default: `{$default}`");
     }
 }
예제 #6
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: ' . preg_replace('/\\s*\\R\\s*/', PHP_EOL . '  ', $option->getDescription() ?: '<none>') . "\n" . '* Default: `' . str_replace("\n", '', var_export($option->getDefault(), true)) . '`');
 }
 /**
  * {@inheritdoc}
  */
 protected function describeInputOption(InputOption $option, array $options = array())
 {
     return $this->output(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()), $options);
 }
예제 #8
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' => preg_replace('/\\s*\\R\\s*/', ' ', $option->getDescription()), 'default' => $option->getDefault());
 }
예제 #9
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');
 }
 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');
     $option = new InputOption('foo', 'f', InputOption::VALUE_NONE);
     try {
         $option->setDefault('default');
         $this->fail('->setDefault() throws an Exception if you give a default value for a VALUE_NONE option');
     } catch (\Exception $e) {
         $this->assertInstanceOf('\\Exception', $e, '->setDefault() throws an Exception if you give a default value for a VALUE_NONE option');
         $this->assertEquals('Cannot set a default value when using Option::VALUE_NONE mode.', $e->getMessage());
     }
     $option = new InputOption('foo', 'f', InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY);
     try {
         $option->setDefault('default');
         $this->fail('->setDefault() throws an Exception if you give a default value which is not an array for a VALUE_IS_ARRAY option');
     } catch (\Exception $e) {
         $this->assertInstanceOf('\\Exception', $e, '->setDefault() throws an Exception if you give a default value which is not an array for a VALUE_IS_ARRAY option');
         $this->assertEquals('A default value for an array option must be an array.', $e->getMessage());
     }
 }
예제 #11
0
파일: InputOption.php 프로젝트: saj696/pipe
 /**
  * Checks whether the given option equals this one.
  *
  * @param InputOption $option option to compare
  *
  * @return bool
  */
 public function equals(InputOption $option)
 {
     return $option->getName() === $this->getName() && $option->getShortcut() === $this->getShortcut() && $option->getDefault() === $this->getDefault() && $option->isArray() === $this->isArray() && $option->isValueRequired() === $this->isValueRequired() && $option->isValueOptional() === $this->isValueOptional();
 }
 protected static function inputOptionSetDescription($inputOption, $description)
 {
     // Recover the 'mode' value, because Symfony is stubborn
     $mode = 0;
     if ($inputOption->isValueRequired()) {
         $mode |= InputOption::VALUE_REQUIRED;
     }
     if ($inputOption->isValueOptional()) {
         $mode |= InputOption::VALUE_OPTIONAL;
     }
     if ($inputOption->isArray()) {
         $mode |= InputOption::VALUE_IS_ARRAY;
     }
     if (!$mode) {
         $mode = InputOption::VALUE_NONE;
     }
     $inputOption = new InputOption($inputOption->getName(), $inputOption->getShortcut(), $mode, $description, $inputOption->getDefault());
     return $inputOption;
 }