From fc2395e237d46030d9c8263417929d3f85387690 Mon Sep 17 00:00:00 2001 From: Maxime STEINHAUSSER Date: Tue, 13 Dec 2016 14:05:04 +0100 Subject: [PATCH 1/3] [Console] MarkdownDescriptor: Link to commands anchors --- .../Console/Descriptor/MarkdownDescriptor.php | 4 ++-- .../Console/Tests/Fixtures/application_1.md | 4 ++-- .../Console/Tests/Fixtures/application_2.md | 12 ++++++------ .../Console/Tests/Fixtures/application_mbstring.md | 6 +++--- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/Symfony/Component/Console/Descriptor/MarkdownDescriptor.php b/src/Symfony/Component/Console/Descriptor/MarkdownDescriptor.php index eb56e06f024d6..6735bb467f230 100644 --- a/src/Symfony/Component/Console/Descriptor/MarkdownDescriptor.php +++ b/src/Symfony/Component/Console/Descriptor/MarkdownDescriptor.php @@ -133,8 +133,8 @@ protected function describeApplication(Application $application, array $options } $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']))); } diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_1.md b/src/Symfony/Component/Console/Tests/Fixtures/application_1.md index 82f426d638d33..c61e07555b28c 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/application_1.md +++ b/src/Symfony/Component/Console/Tests/Fixtures/application_1.md @@ -1,8 +1,8 @@ Console Tool ============ -* `help` -* `list` +* [`help`](#help) +* [`list`](#list) `help` ------ diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_2.md b/src/Symfony/Component/Console/Tests/Fixtures/application_2.md index 68c8b0be1c091..0fb9100805f65 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/application_2.md +++ b/src/Symfony/Component/Console/Tests/Fixtures/application_2.md @@ -1,15 +1,15 @@ My Symfony application v1.0 ======================================== -* `alias1` -* `alias2` -* `help` -* `list` +* [`alias1`](#descriptorcommand1) +* [`alias2`](#descriptorcommand1) +* [`help`](#help) +* [`list`](#list) **descriptor:** -* `descriptor:command1` -* `descriptor:command2` +* [`descriptor:command1`](#descriptorcommand1) +* [`descriptor:command2`](#descriptorcommand2) `help` ------ diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_mbstring.md b/src/Symfony/Component/Console/Tests/Fixtures/application_mbstring.md index 152f56881b15f..5e6388ba31114 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/application_mbstring.md +++ b/src/Symfony/Component/Console/Tests/Fixtures/application_mbstring.md @@ -1,12 +1,12 @@ MbString åpplicätion ==================== -* `help` -* `list` +* [`help`](#help) +* [`list`](#list) **descriptor:** -* `descriptor:åèä` +* [`descriptor:åèä`](#descriptoråèä) `help` ------ From 6896865bcceecf570562179ab8e9b4a366d9b3cf Mon Sep 17 00:00:00 2001 From: Maxime STEINHAUSSER Date: Tue, 13 Dec 2016 16:08:14 +0100 Subject: [PATCH 2/3] [Console] MarkdownDescriptor: Don't use getLongVersion --- .../Console/Descriptor/MarkdownDescriptor.php | 16 +++++++++++++++- .../Console/Tests/Fixtures/application_2.md | 4 ++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/Console/Descriptor/MarkdownDescriptor.php b/src/Symfony/Component/Console/Descriptor/MarkdownDescriptor.php index 6735bb467f230..82fb3865eedb7 100644 --- a/src/Symfony/Component/Console/Descriptor/MarkdownDescriptor.php +++ b/src/Symfony/Component/Console/Descriptor/MarkdownDescriptor.php @@ -123,8 +123,9 @@ protected function describeApplication(Application $application, array $options { $describedNamespace = isset($options['namespace']) ? $options['namespace'] : null; $description = new ApplicationDescription($application, $describedNamespace); + $title = $this->getApplicationTitle($application); - $this->write($application->getLongVersion()."\n".str_repeat('=', Helper::strlen($application->getLongVersion()))); + $this->write($title."\n".str_repeat('=', Helper::strlen($title))); foreach ($description->getNamespaces() as $namespace) { if (ApplicationDescription::GLOBAL_NAMESPACE !== $namespace['id']) { @@ -143,4 +144,17 @@ protected function describeApplication(Application $application, array $options $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'; + } } diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_2.md b/src/Symfony/Component/Console/Tests/Fixtures/application_2.md index 0fb9100805f65..fedc712ab8be9 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/application_2.md +++ b/src/Symfony/Component/Console/Tests/Fixtures/application_2.md @@ -1,5 +1,5 @@ -My Symfony application v1.0 -======================================== +My Symfony application v1.0 +=========================== * [`alias1`](#descriptorcommand1) * [`alias2`](#descriptorcommand1) From ef5b087b4f67868fc80d816f9a45f70e8044651b Mon Sep 17 00:00:00 2001 From: Maxime Steinhausser Date: Mon, 26 Dec 2016 18:25:52 +0100 Subject: [PATCH 3/3] Do not output formatting tags --- .../Console/Descriptor/MarkdownDescriptor.php | 22 +++++++++++++++++++ .../Console/Tests/Fixtures/application_1.md | 22 +++++++++---------- .../Console/Tests/Fixtures/application_2.md | 22 +++++++++---------- .../Tests/Fixtures/application_mbstring.md | 22 +++++++++---------- .../Fixtures/input_argument_with_style.md | 2 +- .../Tests/Fixtures/input_option_with_style.md | 2 +- .../Fixtures/input_option_with_style_array.md | 2 +- 7 files changed, 58 insertions(+), 36 deletions(-) diff --git a/src/Symfony/Component/Console/Descriptor/MarkdownDescriptor.php b/src/Symfony/Component/Console/Descriptor/MarkdownDescriptor.php index 82fb3865eedb7..106bff5114992 100644 --- a/src/Symfony/Component/Console/Descriptor/MarkdownDescriptor.php +++ b/src/Symfony/Component/Console/Descriptor/MarkdownDescriptor.php @@ -17,6 +17,7 @@ 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. @@ -27,6 +28,27 @@ */ 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} */ diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_1.md b/src/Symfony/Component/Console/Tests/Fixtures/application_1.md index c61e07555b28c..b46c975a79082 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/application_1.md +++ b/src/Symfony/Component/Console/Tests/Fixtures/application_1.md @@ -13,15 +13,15 @@ Displays help for a command * `help [--format FORMAT] [--raw] [--] []` -The help command displays help for a given command: +The help command displays help for a given command: - php app/console help list + php app/console help list -You can also output the help in other formats by using the --format option: +You can also output the help in other formats by using the --format option: - php app/console help --format=xml list + php app/console help --format=xml list -To display the list of available commands, please use the list command. +To display the list of available commands, please use the list command. ### Arguments @@ -125,21 +125,21 @@ Lists commands * `list [--raw] [--format FORMAT] [--] []` -The list command lists all commands: +The list command lists all commands: - php app/console list + php app/console list You can also display the commands for a specific namespace: - php app/console list test + php app/console list test -You can also output the information in other formats by using the --format option: +You can also output the information in other formats by using the --format option: - php app/console list --format=xml + php app/console list --format=xml It's also possible to get raw list of commands (useful for embedding command runner): - php app/console list --raw + php app/console list --raw ### Arguments diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_2.md b/src/Symfony/Component/Console/Tests/Fixtures/application_2.md index fedc712ab8be9..14da75e458665 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/application_2.md +++ b/src/Symfony/Component/Console/Tests/Fixtures/application_2.md @@ -20,15 +20,15 @@ Displays help for a command * `help [--format FORMAT] [--raw] [--] []` -The help command displays help for a given command: +The help command displays help for a given command: - php app/console help list + php app/console help list -You can also output the help in other formats by using the --format option: +You can also output the help in other formats by using the --format option: - php app/console help --format=xml list + php app/console help --format=xml list -To display the list of available commands, please use the list command. +To display the list of available commands, please use the list command. ### Arguments @@ -132,21 +132,21 @@ Lists commands * `list [--raw] [--format FORMAT] [--] []` -The list command lists all commands: +The list command lists all commands: - php app/console list + php app/console list You can also display the commands for a specific namespace: - php app/console list test + php app/console list test -You can also output the information in other formats by using the --format option: +You can also output the information in other formats by using the --format option: - php app/console list --format=xml + php app/console list --format=xml It's also possible to get raw list of commands (useful for embedding command runner): - php app/console list --raw + php app/console list --raw ### Arguments diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_mbstring.md b/src/Symfony/Component/Console/Tests/Fixtures/application_mbstring.md index 5e6388ba31114..f34e5585cf399 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/application_mbstring.md +++ b/src/Symfony/Component/Console/Tests/Fixtures/application_mbstring.md @@ -17,15 +17,15 @@ Displays help for a command * `help [--format FORMAT] [--raw] [--] []` -The help command displays help for a given command: +The help command displays help for a given command: - php app/console help list + php app/console help list -You can also output the help in other formats by using the --format option: +You can also output the help in other formats by using the --format option: - php app/console help --format=xml list + php app/console help --format=xml list -To display the list of available commands, please use the list command. +To display the list of available commands, please use the list command. ### Arguments @@ -129,21 +129,21 @@ Lists commands * `list [--raw] [--format FORMAT] [--] []` -The list command lists all commands: +The list command lists all commands: - php app/console list + php app/console list You can also display the commands for a specific namespace: - php app/console list test + php app/console list test -You can also output the information in other formats by using the --format option: +You can also output the information in other formats by using the --format option: - php app/console list --format=xml + php app/console list --format=xml It's also possible to get raw list of commands (useful for embedding command runner): - php app/console list --raw + php app/console list --raw ### Arguments diff --git a/src/Symfony/Component/Console/Tests/Fixtures/input_argument_with_style.md b/src/Symfony/Component/Console/Tests/Fixtures/input_argument_with_style.md index af494422d10de..a2be96721fb2a 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/input_argument_with_style.md +++ b/src/Symfony/Component/Console/Tests/Fixtures/input_argument_with_style.md @@ -4,4 +4,4 @@ argument description * Is required: no * Is array: no -* Default: `'style'` +* Default: `'style'` diff --git a/src/Symfony/Component/Console/Tests/Fixtures/input_option_with_style.md b/src/Symfony/Component/Console/Tests/Fixtures/input_option_with_style.md index fca9ac74854e9..e07a5643a972f 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/input_option_with_style.md +++ b/src/Symfony/Component/Console/Tests/Fixtures/input_option_with_style.md @@ -5,4 +5,4 @@ option description * Accept value: yes * Is value required: yes * Is multiple: no -* Default: `'style'` +* Default: `'style'` diff --git a/src/Symfony/Component/Console/Tests/Fixtures/input_option_with_style_array.md b/src/Symfony/Component/Console/Tests/Fixtures/input_option_with_style_array.md index f16ef73e58fd9..16a045bcffb6a 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/input_option_with_style_array.md +++ b/src/Symfony/Component/Console/Tests/Fixtures/input_option_with_style_array.md @@ -5,4 +5,4 @@ option description * Accept value: yes * Is value required: yes * Is multiple: yes -* Default: `array ( 0 => 'Hello', 1 => 'world',)` +* Default: `array ( 0 => 'Hello', 1 => 'world',)`