summaryrefslogtreecommitdiff
path: root/vendor/symfony/console/Descriptor/MarkdownDescriptor.php
diff options
context:
space:
mode:
authorFrédéric Guillot <fred@kanboard.net>2017-12-15 11:24:35 -0800
committerFrédéric Guillot <fred@kanboard.net>2017-12-15 11:55:42 -0800
commita93b8e10f5954be0853eec693c13e84c4bd9e6f2 (patch)
treeeda5de9494b819235616e8623bb3393e9cc373af /vendor/symfony/console/Descriptor/MarkdownDescriptor.php
parent2c72a283f2d51034f85f4e2ca8b194d304a3c433 (diff)
Kanboard requires at least PHP 5.6 now
Diffstat (limited to 'vendor/symfony/console/Descriptor/MarkdownDescriptor.php')
-rw-r--r--vendor/symfony/console/Descriptor/MarkdownDescriptor.php73
1 files changed, 56 insertions, 17 deletions
diff --git a/vendor/symfony/console/Descriptor/MarkdownDescriptor.php b/vendor/symfony/console/Descriptor/MarkdownDescriptor.php
index d3d76a42..106bff51 100644
--- a/vendor/symfony/console/Descriptor/MarkdownDescriptor.php
+++ b/vendor/symfony/console/Descriptor/MarkdownDescriptor.php
@@ -13,9 +13,11 @@ namespace Symfony\Component\Console\Descriptor;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Command\Command;
+use Symfony\Component\Console\Helper\Helper;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputDefinition;
use Symfony\Component\Console\Input\InputOption;
+use Symfony\Component\Console\Output\OutputInterface;
/**
* Markdown descriptor.
@@ -29,14 +31,34 @@ class MarkdownDescriptor extends Descriptor
/**
* {@inheritdoc}
*/
+ public function describe(OutputInterface $output, $object, array $options = array())
+ {
+ $decorated = $output->isDecorated();
+ $output->setDecorated(false);
+
+ parent::describe($output, $object, $options);
+
+ $output->setDecorated($decorated);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function write($content, $decorated = true)
+ {
+ parent::write($content, $decorated);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
protected function describeInputArgument(InputArgument $argument, array $options = array())
{
$this->write(
- '**'.$argument->getName().':**'."\n\n"
- .'* Name: '.($argument->getName() ?: '<none>')."\n"
+ '#### `'.($argument->getName() ?: '<none>')."`\n\n"
+ .($argument->getDescription() ? preg_replace('/\s*[\r\n]\s*/', "\n", $argument->getDescription())."\n\n" : '')
.'* Is required: '.($argument->isRequired() ? 'yes' : 'no')."\n"
.'* Is array: '.($argument->isArray() ? 'yes' : 'no')."\n"
- .'* Description: '.preg_replace('/\s*[\r\n]\s*/', "\n ", $argument->getDescription() ?: '<none>')."\n"
.'* Default: `'.str_replace("\n", '', var_export($argument->getDefault(), true)).'`'
);
}
@@ -46,14 +68,17 @@ class MarkdownDescriptor extends Descriptor
*/
protected function describeInputOption(InputOption $option, array $options = array())
{
+ $name = '--'.$option->getName();
+ if ($option->getShortcut()) {
+ $name .= '|-'.implode('|-', explode('|', $option->getShortcut())).'';
+ }
+
$this->write(
- '**'.$option->getName().':**'."\n\n"
- .'* Name: `--'.$option->getName().'`'."\n"
- .'* Shortcut: '.($option->getShortcut() ? '`-'.implode('|-', explode('|', $option->getShortcut())).'`' : '<none>')."\n"
+ '#### `'.$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"
- .'* Description: '.preg_replace('/\s*[\r\n]\s*/', "\n ", $option->getDescription() ?: '<none>')."\n"
.'* Default: `'.str_replace("\n", '', var_export($option->getDefault(), true)).'`'
);
}
@@ -64,7 +89,7 @@ class MarkdownDescriptor extends Descriptor
protected function describeInputDefinition(InputDefinition $definition, array $options = array())
{
if ($showArguments = count($definition->getArguments()) > 0) {
- $this->write('### Arguments:');
+ $this->write('### Arguments');
foreach ($definition->getArguments() as $argument) {
$this->write("\n\n");
$this->write($this->describeInputArgument($argument));
@@ -76,7 +101,7 @@ class MarkdownDescriptor extends Descriptor
$this->write("\n\n");
}
- $this->write('### Options:');
+ $this->write('### Options');
foreach ($definition->getOptions() as $option) {
$this->write("\n\n");
$this->write($this->describeInputOption($option));
@@ -93,12 +118,12 @@ class MarkdownDescriptor extends Descriptor
$command->mergeApplicationDefinition(false);
$this->write(
- $command->getName()."\n"
- .str_repeat('-', strlen($command->getName()))."\n\n"
- .'* Description: '.($command->getDescription() ?: '<none>')."\n"
- .'* Usage:'."\n\n"
+ '`'.$command->getName()."`\n"
+ .str_repeat('-', Helper::strlen($command->getName()) + 2)."\n\n"
+ .($command->getDescription() ? $command->getDescription()."\n\n" : '')
+ .'### Usage'."\n\n"
.array_reduce(array_merge(array($command->getSynopsis()), $command->getAliases(), $command->getUsages()), function ($carry, $usage) {
- return $carry .= ' * `'.$usage.'`'."\n";
+ return $carry.'* `'.$usage.'`'."\n";
})
);
@@ -120,8 +145,9 @@ class MarkdownDescriptor extends Descriptor
{
$describedNamespace = isset($options['namespace']) ? $options['namespace'] : null;
$description = new ApplicationDescription($application, $describedNamespace);
+ $title = $this->getApplicationTitle($application);
- $this->write($application->getName()."\n".str_repeat('=', strlen($application->getName())));
+ $this->write($title."\n".str_repeat('=', Helper::strlen($title)));
foreach ($description->getNamespaces() as $namespace) {
if (ApplicationDescription::GLOBAL_NAMESPACE !== $namespace['id']) {
@@ -130,8 +156,8 @@ class MarkdownDescriptor extends Descriptor
}
$this->write("\n\n");
- $this->write(implode("\n", array_map(function ($commandName) {
- return '* '.$commandName;
+ $this->write(implode("\n", array_map(function ($commandName) use ($description) {
+ return sprintf('* [`%s`](#%s)', $commandName, str_replace(':', '', $description->getCommand($commandName)->getName()));
}, $namespace['commands'])));
}
@@ -140,4 +166,17 @@ class MarkdownDescriptor extends Descriptor
$this->write($this->describeCommand($command));
}
}
+
+ private function getApplicationTitle(Application $application)
+ {
+ if ('UNKNOWN' !== $application->getName()) {
+ if ('UNKNOWN' !== $application->getVersion()) {
+ return sprintf('%s %s', $application->getName(), $application->getVersion());
+ }
+
+ return $application->getName();
+ }
+
+ return 'Console Tool';
+ }
}