From 0cc09cf3e54b78de7d9461a7f086a289f1f659a2 Mon Sep 17 00:00:00 2001 From: Maxime STEINHAUSSER Date: Tue, 13 Dec 2016 15:25:44 +0100 Subject: [PATCH 1/2] [Console] Descriptors should use Helper::strlen --- .../Console/Descriptor/MarkdownDescriptor.php | 5 +- .../Console/Descriptor/TextDescriptor.php | 17 +- .../Tests/Descriptor/ObjectsProvider.php | 4 + .../DescriptorApplicationMbString.php | 24 ++ .../Fixtures/DescriptorCommandMbString.php | 32 ++ .../Tests/Fixtures/application_mbstring.json | 273 ++++++++++++++++ .../Tests/Fixtures/application_mbstring.md | 309 ++++++++++++++++++ .../Tests/Fixtures/application_mbstring.txt | 19 ++ .../Tests/Fixtures/application_mbstring.xml | 154 +++++++++ .../Tests/Fixtures/command_mbstring.json | 32 ++ .../Tests/Fixtures/command_mbstring.md | 33 ++ .../Tests/Fixtures/command_mbstring.txt | 13 + .../Tests/Fixtures/command_mbstring.xml | 21 ++ 13 files changed, 926 insertions(+), 10 deletions(-) create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/DescriptorApplicationMbString.php create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/DescriptorCommandMbString.php create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/application_mbstring.json create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/application_mbstring.md create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/application_mbstring.txt create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/application_mbstring.xml create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/command_mbstring.json create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/command_mbstring.md create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/command_mbstring.txt create mode 100644 src/Symfony/Component/Console/Tests/Fixtures/command_mbstring.xml diff --git a/src/Symfony/Component/Console/Descriptor/MarkdownDescriptor.php b/src/Symfony/Component/Console/Descriptor/MarkdownDescriptor.php index 2eb9944d6213c..c2d6243e280cc 100644 --- a/src/Symfony/Component/Console/Descriptor/MarkdownDescriptor.php +++ b/src/Symfony/Component/Console/Descriptor/MarkdownDescriptor.php @@ -13,6 +13,7 @@ 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; @@ -94,7 +95,7 @@ protected function describeCommand(Command $command, array $options = array()) $this->write( $command->getName()."\n" - .str_repeat('-', strlen($command->getName()))."\n\n" + .str_repeat('-', Helper::strlen($command->getName()))."\n\n" .'* Description: '.($command->getDescription() ?: '')."\n" .'* Usage:'."\n\n" .array_reduce(array_merge(array($command->getSynopsis()), $command->getAliases(), $command->getUsages()), function ($carry, $usage) { @@ -121,7 +122,7 @@ protected function describeApplication(Application $application, array $options $describedNamespace = isset($options['namespace']) ? $options['namespace'] : null; $description = new ApplicationDescription($application, $describedNamespace); - $this->write($application->getName()."\n".str_repeat('=', strlen($application->getName()))); + $this->write($application->getName()."\n".str_repeat('=', Helper::strlen($application->getName()))); foreach ($description->getNamespaces() as $namespace) { if (ApplicationDescription::GLOBAL_NAMESPACE !== $namespace['id']) { diff --git a/src/Symfony/Component/Console/Descriptor/TextDescriptor.php b/src/Symfony/Component/Console/Descriptor/TextDescriptor.php index eb02c89dfa372..c18ed6f22490b 100644 --- a/src/Symfony/Component/Console/Descriptor/TextDescriptor.php +++ b/src/Symfony/Component/Console/Descriptor/TextDescriptor.php @@ -13,6 +13,7 @@ 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; @@ -37,7 +38,7 @@ protected function describeInputArgument(InputArgument $argument, array $options $default = ''; } - $totalWidth = isset($options['total_width']) ? $options['total_width'] : strlen($argument->getName()); + $totalWidth = isset($options['total_width']) ? $options['total_width'] : Helper::strlen($argument->getName()); $spacingWidth = $totalWidth - strlen($argument->getName()); $this->writeText(sprintf(' %s %s%s%s', @@ -75,7 +76,7 @@ protected function describeInputOption(InputOption $option, array $options = arr sprintf('--%s%s', $option->getName(), $value) ); - $spacingWidth = $totalWidth - strlen($synopsis); + $spacingWidth = $totalWidth - Helper::strlen($synopsis); $this->writeText(sprintf(' %s %s%s%s%s', $synopsis, @@ -94,7 +95,7 @@ protected function describeInputDefinition(InputDefinition $definition, array $o { $totalWidth = $this->calculateTotalWidthForOptions($definition->getOptions()); foreach ($definition->getArguments() as $argument) { - $totalWidth = max($totalWidth, strlen($argument->getName())); + $totalWidth = max($totalWidth, Helper::strlen($argument->getName())); } if ($definition->getArguments()) { @@ -206,7 +207,7 @@ protected function describeApplication(Application $application, array $options foreach ($namespace['commands'] as $name) { $this->writeText("\n"); - $spacingWidth = $width - strlen($name); + $spacingWidth = $width - Helper::strlen($name); $this->writeText(sprintf(' %s%s%s', $name, str_repeat(' ', $spacingWidth), $description->getCommand($name)->getDescription()), $options); } } @@ -252,9 +253,9 @@ private function getColumnWidth(array $commands) $widths = array(); foreach ($commands as $command) { - $widths[] = strlen($command->getName()); + $widths[] = Helper::strlen($command->getName()); foreach ($command->getAliases() as $alias) { - $widths[] = strlen($alias); + $widths[] = Helper::strlen($alias); } } @@ -271,10 +272,10 @@ private function calculateTotalWidthForOptions($options) $totalWidth = 0; foreach ($options as $option) { // "-" + shortcut + ", --" + name - $nameLength = 1 + max(strlen($option->getShortcut()), 1) + 4 + strlen($option->getName()); + $nameLength = 1 + max(strlen($option->getShortcut()), 1) + 4 + Helper::strlen($option->getName()); if ($option->acceptValue()) { - $valueLength = 1 + strlen($option->getName()); // = + value + $valueLength = 1 + Helper::strlen($option->getName()); // = + value $valueLength += $option->isValueOptional() ? 2 : 0; // [ + ] $nameLength += $valueLength; diff --git a/src/Symfony/Component/Console/Tests/Descriptor/ObjectsProvider.php b/src/Symfony/Component/Console/Tests/Descriptor/ObjectsProvider.php index 45b3b2fff9034..26ea7602e6953 100644 --- a/src/Symfony/Component/Console/Tests/Descriptor/ObjectsProvider.php +++ b/src/Symfony/Component/Console/Tests/Descriptor/ObjectsProvider.php @@ -16,8 +16,10 @@ use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Tests\Fixtures\DescriptorApplication1; use Symfony\Component\Console\Tests\Fixtures\DescriptorApplication2; +use Symfony\Component\Console\Tests\Fixtures\DescriptorApplicationMbString; use Symfony\Component\Console\Tests\Fixtures\DescriptorCommand1; use Symfony\Component\Console\Tests\Fixtures\DescriptorCommand2; +use Symfony\Component\Console\Tests\Fixtures\DescriptorCommandMbString; /** * @author Jean-François Simon @@ -64,6 +66,7 @@ public static function getCommands() return array( 'command_1' => new DescriptorCommand1(), 'command_2' => new DescriptorCommand2(), + 'command_mbstring' => new DescriptorCommandMbString(), ); } @@ -72,6 +75,7 @@ public static function getApplications() return array( 'application_1' => new DescriptorApplication1(), 'application_2' => new DescriptorApplication2(), + 'application_mbstring' => new DescriptorApplicationMbString(), ); } } diff --git a/src/Symfony/Component/Console/Tests/Fixtures/DescriptorApplicationMbString.php b/src/Symfony/Component/Console/Tests/Fixtures/DescriptorApplicationMbString.php new file mode 100644 index 0000000000000..bf170c449f51e --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/DescriptorApplicationMbString.php @@ -0,0 +1,24 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Console\Tests\Fixtures; + +use Symfony\Component\Console\Application; + +class DescriptorApplicationMbString extends Application +{ + public function __construct() + { + parent::__construct('MbString åpplicätion'); + + $this->add(new DescriptorCommandMbString()); + } +} diff --git a/src/Symfony/Component/Console/Tests/Fixtures/DescriptorCommandMbString.php b/src/Symfony/Component/Console/Tests/Fixtures/DescriptorCommandMbString.php new file mode 100644 index 0000000000000..66de917e29f58 --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/DescriptorCommandMbString.php @@ -0,0 +1,32 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Console\Tests\Fixtures; + +use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Input\InputOption; + +class DescriptorCommandMbString extends Command +{ + protected function configure() + { + $this + ->setName('descriptor:åèä') + ->setDescription('command åèä description') + ->setHelp('command åèä help') + ->addUsage('-o|--option_name ') + ->addUsage('') + ->addArgument('argument_åèä', InputArgument::REQUIRED) + ->addOption('option_åèä', 'o', InputOption::VALUE_NONE) + ; + } +} diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_mbstring.json b/src/Symfony/Component/Console/Tests/Fixtures/application_mbstring.json new file mode 100644 index 0000000000000..81c668395b045 --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/application_mbstring.json @@ -0,0 +1,273 @@ +{ + "commands": [ + { + "name": "help", + "usage": [ + "help [--xml] [--format FORMAT] [--raw] [--] []" + ], + "description": "Displays help for a command", + "help": "The help<\/info> command displays help for a given command:\n\n php app\/console help list<\/info>\n\nYou can also output the help in other formats by using the --format<\/comment> option:\n\n php app\/console help --format=xml list<\/info>\n\nTo display the list of available commands, please use the list<\/info> command.", + "definition": { + "arguments": { + "command_name": { + "name": "command_name", + "is_required": false, + "is_array": false, + "description": "The command name", + "default": "help" + } + }, + "options": { + "xml": { + "name": "--xml", + "shortcut": "", + "accept_value": false, + "is_value_required": false, + "is_multiple": false, + "description": "To output help as XML", + "default": false + }, + "format": { + "name": "--format", + "shortcut": "", + "accept_value": true, + "is_value_required": true, + "is_multiple": false, + "description": "The output format (txt, xml, json, or md)", + "default": "txt" + }, + "raw": { + "name": "--raw", + "shortcut": "", + "accept_value": false, + "is_value_required": false, + "is_multiple": false, + "description": "To output raw command help", + "default": false + }, + "help": { + "name": "--help", + "shortcut": "-h", + "accept_value": false, + "is_value_required": false, + "is_multiple": false, + "description": "Display this help message", + "default": false + }, + "quiet": { + "name": "--quiet", + "shortcut": "-q", + "accept_value": false, + "is_value_required": false, + "is_multiple": false, + "description": "Do not output any message", + "default": false + }, + "verbose": { + "name": "--verbose", + "shortcut": "-v|-vv|-vvv", + "accept_value": false, + "is_value_required": false, + "is_multiple": false, + "description": "Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug", + "default": false + }, + "version": { + "name": "--version", + "shortcut": "-V", + "accept_value": false, + "is_value_required": false, + "is_multiple": false, + "description": "Display this application version", + "default": false + }, + "ansi": { + "name": "--ansi", + "shortcut": "", + "accept_value": false, + "is_value_required": false, + "is_multiple": false, + "description": "Force ANSI output", + "default": false + }, + "no-ansi": { + "name": "--no-ansi", + "shortcut": "", + "accept_value": false, + "is_value_required": false, + "is_multiple": false, + "description": "Disable ANSI output", + "default": false + }, + "no-interaction": { + "name": "--no-interaction", + "shortcut": "-n", + "accept_value": false, + "is_value_required": false, + "is_multiple": false, + "description": "Do not ask any interactive question", + "default": false + } + } + } + }, + { + "name": "list", + "usage": [ + "list [--xml] [--raw] [--format FORMAT] [--] []" + ], + "description": "Lists commands", + "help": "The list<\/info> command lists all commands:\n\n php app\/console list<\/info>\n\nYou can also display the commands for a specific namespace:\n\n php app\/console list test<\/info>\n\nYou can also output the information in other formats by using the --format<\/comment> option:\n\n php app\/console list --format=xml<\/info>\n\nIt's also possible to get raw list of commands (useful for embedding command runner):\n\n php app\/console list --raw<\/info>", + "definition": { + "arguments": { + "namespace": { + "name": "namespace", + "is_required": false, + "is_array": false, + "description": "The namespace name", + "default": null + } + }, + "options": { + "xml": { + "name": "--xml", + "shortcut": "", + "accept_value": false, + "is_value_required": false, + "is_multiple": false, + "description": "To output list as XML", + "default": false + }, + "raw": { + "name": "--raw", + "shortcut": "", + "accept_value": false, + "is_value_required": false, + "is_multiple": false, + "description": "To output raw command list", + "default": false + }, + "format": { + "name": "--format", + "shortcut": "", + "accept_value": true, + "is_value_required": true, + "is_multiple": false, + "description": "The output format (txt, xml, json, or md)", + "default": "txt" + } + } + } + }, + { + "name": "descriptor:\u00e5\u00e8\u00e4", + "usage": [ + "descriptor:\u00e5\u00e8\u00e4 [-o|--option_\u00e5\u00e8\u00e4] [--] ", + "descriptor:\u00e5\u00e8\u00e4 -o|--option_name ", + "descriptor:\u00e5\u00e8\u00e4 " + ], + "description": "command \u00e5\u00e8\u00e4 description", + "help": "command \u00e5\u00e8\u00e4 help", + "definition": { + "arguments": { + "argument_\u00e5\u00e8\u00e4": { + "name": "argument_\u00e5\u00e8\u00e4", + "is_required": true, + "is_array": false, + "description": "", + "default": null + } + }, + "options": { + "option_\u00e5\u00e8\u00e4": { + "name": "--option_\u00e5\u00e8\u00e4", + "shortcut": "-o", + "accept_value": false, + "is_value_required": false, + "is_multiple": false, + "description": "", + "default": false + }, + "help": { + "name": "--help", + "shortcut": "-h", + "accept_value": false, + "is_value_required": false, + "is_multiple": false, + "description": "Display this help message", + "default": false + }, + "quiet": { + "name": "--quiet", + "shortcut": "-q", + "accept_value": false, + "is_value_required": false, + "is_multiple": false, + "description": "Do not output any message", + "default": false + }, + "verbose": { + "name": "--verbose", + "shortcut": "-v|-vv|-vvv", + "accept_value": false, + "is_value_required": false, + "is_multiple": false, + "description": "Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug", + "default": false + }, + "version": { + "name": "--version", + "shortcut": "-V", + "accept_value": false, + "is_value_required": false, + "is_multiple": false, + "description": "Display this application version", + "default": false + }, + "ansi": { + "name": "--ansi", + "shortcut": "", + "accept_value": false, + "is_value_required": false, + "is_multiple": false, + "description": "Force ANSI output", + "default": false + }, + "no-ansi": { + "name": "--no-ansi", + "shortcut": "", + "accept_value": false, + "is_value_required": false, + "is_multiple": false, + "description": "Disable ANSI output", + "default": false + }, + "no-interaction": { + "name": "--no-interaction", + "shortcut": "-n", + "accept_value": false, + "is_value_required": false, + "is_multiple": false, + "description": "Do not ask any interactive question", + "default": false + } + } + } + } + ], + "namespaces": [ + { + "id": "_global", + "commands": [ + "help", + "list" + ] + }, + { + "id": "descriptor", + "commands": [ + "descriptor:\u00e5\u00e8\u00e4" + ] + } + ] +} diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_mbstring.md b/src/Symfony/Component/Console/Tests/Fixtures/application_mbstring.md new file mode 100644 index 0000000000000..ef81f8697268b --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/application_mbstring.md @@ -0,0 +1,309 @@ +MbString åpplicätion +==================== + +* help +* list + +**descriptor:** + +* descriptor:åèä + +help +---- + +* Description: Displays help for a command +* Usage: + + * `help [--xml] [--format FORMAT] [--raw] [--] []` + +The help command displays help for a given command: + + php app/console help list + +You can also output the help in other formats by using the --format option: + + php app/console help --format=xml list + +To display the list of available commands, please use the list command. + +### Arguments: + +**command_name:** + +* Name: command_name +* Is required: no +* Is array: no +* Description: The command name +* Default: `'help'` + +### Options: + +**xml:** + +* Name: `--xml` +* Shortcut: +* Accept value: no +* Is value required: no +* Is multiple: no +* Description: To output help as XML +* Default: `false` + +**format:** + +* Name: `--format` +* Shortcut: +* Accept value: yes +* Is value required: yes +* Is multiple: no +* Description: The output format (txt, xml, json, or md) +* Default: `'txt'` + +**raw:** + +* Name: `--raw` +* Shortcut: +* Accept value: no +* Is value required: no +* Is multiple: no +* Description: To output raw command help +* Default: `false` + +**help:** + +* Name: `--help` +* Shortcut: `-h` +* Accept value: no +* Is value required: no +* Is multiple: no +* Description: Display this help message +* Default: `false` + +**quiet:** + +* Name: `--quiet` +* Shortcut: `-q` +* Accept value: no +* Is value required: no +* Is multiple: no +* Description: Do not output any message +* Default: `false` + +**verbose:** + +* Name: `--verbose` +* Shortcut: `-v|-vv|-vvv` +* Accept value: no +* Is value required: no +* Is multiple: no +* Description: Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug +* Default: `false` + +**version:** + +* Name: `--version` +* Shortcut: `-V` +* Accept value: no +* Is value required: no +* Is multiple: no +* Description: Display this application version +* Default: `false` + +**ansi:** + +* Name: `--ansi` +* Shortcut: +* Accept value: no +* Is value required: no +* Is multiple: no +* Description: Force ANSI output +* Default: `false` + +**no-ansi:** + +* Name: `--no-ansi` +* Shortcut: +* Accept value: no +* Is value required: no +* Is multiple: no +* Description: Disable ANSI output +* Default: `false` + +**no-interaction:** + +* Name: `--no-interaction` +* Shortcut: `-n` +* Accept value: no +* Is value required: no +* Is multiple: no +* Description: Do not ask any interactive question +* Default: `false` + +list +---- + +* Description: Lists commands +* Usage: + + * `list [--xml] [--raw] [--format FORMAT] [--] []` + +The list command lists all commands: + + php app/console list + +You can also display the commands for a specific namespace: + + php app/console list test + +You can also output the information in other formats by using the --format option: + + 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 + +### Arguments: + +**namespace:** + +* Name: namespace +* Is required: no +* Is array: no +* Description: The namespace name +* Default: `NULL` + +### Options: + +**xml:** + +* Name: `--xml` +* Shortcut: +* Accept value: no +* Is value required: no +* Is multiple: no +* Description: To output list as XML +* Default: `false` + +**raw:** + +* Name: `--raw` +* Shortcut: +* Accept value: no +* Is value required: no +* Is multiple: no +* Description: To output raw command list +* Default: `false` + +**format:** + +* Name: `--format` +* Shortcut: +* Accept value: yes +* Is value required: yes +* Is multiple: no +* Description: The output format (txt, xml, json, or md) +* Default: `'txt'` + +descriptor:åèä +-------------- + +* Description: command åèä description +* Usage: + + * `descriptor:åèä [-o|--option_åèä] [--] ` + * `descriptor:åèä -o|--option_name ` + * `descriptor:åèä ` + +command åèä help + +### Arguments: + +**argument_åèä:** + +* Name: argument_åèä +* Is required: yes +* Is array: no +* Description: +* Default: `NULL` + +### Options: + +**option_åèä:** + +* Name: `--option_åèä` +* Shortcut: `-o` +* Accept value: no +* Is value required: no +* Is multiple: no +* Description: +* Default: `false` + +**help:** + +* Name: `--help` +* Shortcut: `-h` +* Accept value: no +* Is value required: no +* Is multiple: no +* Description: Display this help message +* Default: `false` + +**quiet:** + +* Name: `--quiet` +* Shortcut: `-q` +* Accept value: no +* Is value required: no +* Is multiple: no +* Description: Do not output any message +* Default: `false` + +**verbose:** + +* Name: `--verbose` +* Shortcut: `-v|-vv|-vvv` +* Accept value: no +* Is value required: no +* Is multiple: no +* Description: Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug +* Default: `false` + +**version:** + +* Name: `--version` +* Shortcut: `-V` +* Accept value: no +* Is value required: no +* Is multiple: no +* Description: Display this application version +* Default: `false` + +**ansi:** + +* Name: `--ansi` +* Shortcut: +* Accept value: no +* Is value required: no +* Is multiple: no +* Description: Force ANSI output +* Default: `false` + +**no-ansi:** + +* Name: `--no-ansi` +* Shortcut: +* Accept value: no +* Is value required: no +* Is multiple: no +* Description: Disable ANSI output +* Default: `false` + +**no-interaction:** + +* Name: `--no-interaction` +* Shortcut: `-n` +* Accept value: no +* Is value required: no +* Is multiple: no +* Description: Do not ask any interactive question +* Default: `false` diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_mbstring.txt b/src/Symfony/Component/Console/Tests/Fixtures/application_mbstring.txt new file mode 100644 index 0000000000000..9d21f829d505e --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/application_mbstring.txt @@ -0,0 +1,19 @@ +MbString åpplicätion + +Usage: + command [options] [arguments] + +Options: + -h, --help Display this help message + -q, --quiet Do not output any message + -V, --version Display this application version + --ansi Force ANSI output + --no-ansi Disable ANSI output + -n, --no-interaction Do not ask any interactive question + -v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug + +Available commands: + help Displays help for a command + list Lists commands + descriptor + descriptor:åèä command åèä description diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_mbstring.xml b/src/Symfony/Component/Console/Tests/Fixtures/application_mbstring.xml new file mode 100644 index 0000000000000..e513d624876e7 --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/application_mbstring.xml @@ -0,0 +1,154 @@ + + + + + + help [--xml] [--format FORMAT] [--raw] [--] [<command_name>] + + Displays help for a command + The <info>help</info> command displays help for a given command: + + <info>php app/console help list</info> + + You can also output the help in other formats by using the <comment>--format</comment> option: + + <info>php app/console help --format=xml list</info> + + To display the list of available commands, please use the <info>list</info> command. + + + The command name + + help + + + + + + + + + + + + + + + + + + + list [--xml] [--raw] [--format FORMAT] [--] [<namespace>] + + Lists commands + The <info>list</info> command lists all commands: + + <info>php app/console list</info> + + You can also display the commands for a specific namespace: + + <info>php app/console list test</info> + + You can also output the information in other formats by using the <comment>--format</comment> option: + + <info>php app/console list --format=xml</info> + + It's also possible to get raw list of commands (useful for embedding command runner): + + <info>php app/console list --raw</info> + + + The namespace name + + + + + + + + + + + + descriptor:åèä [-o|--option_åèä] [--] <argument_åèä> + descriptor:åèä -o|--option_name <argument_name> + descriptor:åèä <argument_name> + + command åèä description + command åèä help + + + + + + + + + + + + + + + + + + + + + help + list + + + descriptor:åèä + + + diff --git a/src/Symfony/Component/Console/Tests/Fixtures/command_mbstring.json b/src/Symfony/Component/Console/Tests/Fixtures/command_mbstring.json new file mode 100644 index 0000000000000..5b8998971af97 --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/command_mbstring.json @@ -0,0 +1,32 @@ +{ + "name": "descriptor:\u00e5\u00e8\u00e4", + "usage": [ + "descriptor:\u00e5\u00e8\u00e4 [-o|--option_\u00e5\u00e8\u00e4] [--] ", + "descriptor:\u00e5\u00e8\u00e4 -o|--option_name ", + "descriptor:\u00e5\u00e8\u00e4 " + ], + "description": "command \u00e5\u00e8\u00e4 description", + "help": "command \u00e5\u00e8\u00e4 help", + "definition": { + "arguments": { + "argument_\u00e5\u00e8\u00e4": { + "name": "argument_\u00e5\u00e8\u00e4", + "is_required": true, + "is_array": false, + "description": "", + "default": null + } + }, + "options": { + "option_\u00e5\u00e8\u00e4": { + "name": "--option_\u00e5\u00e8\u00e4", + "shortcut": "-o", + "accept_value": false, + "is_value_required": false, + "is_multiple": false, + "description": "", + "default": false + } + } + } +} diff --git a/src/Symfony/Component/Console/Tests/Fixtures/command_mbstring.md b/src/Symfony/Component/Console/Tests/Fixtures/command_mbstring.md new file mode 100644 index 0000000000000..2adac53f05fb8 --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/command_mbstring.md @@ -0,0 +1,33 @@ +descriptor:åèä +-------------- + +* Description: command åèä description +* Usage: + + * `descriptor:åèä [-o|--option_åèä] [--] ` + * `descriptor:åèä -o|--option_name ` + * `descriptor:åèä ` + +command åèä help + +### Arguments: + +**argument_åèä:** + +* Name: argument_åèä +* Is required: yes +* Is array: no +* Description: +* Default: `NULL` + +### Options: + +**option_åèä:** + +* Name: `--option_åèä` +* Shortcut: `-o` +* Accept value: no +* Is value required: no +* Is multiple: no +* Description: +* Default: `false` diff --git a/src/Symfony/Component/Console/Tests/Fixtures/command_mbstring.txt b/src/Symfony/Component/Console/Tests/Fixtures/command_mbstring.txt new file mode 100644 index 0000000000000..969a0652420b2 --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/command_mbstring.txt @@ -0,0 +1,13 @@ +Usage: + descriptor:åèä [options] [--] + descriptor:åèä -o|--option_name + descriptor:åèä + +Arguments: + argument_åèä + +Options: + -o, --option_åèä + +Help: + command åèä help diff --git a/src/Symfony/Component/Console/Tests/Fixtures/command_mbstring.xml b/src/Symfony/Component/Console/Tests/Fixtures/command_mbstring.xml new file mode 100644 index 0000000000000..e9f1a750692b6 --- /dev/null +++ b/src/Symfony/Component/Console/Tests/Fixtures/command_mbstring.xml @@ -0,0 +1,21 @@ + + + + descriptor:åèä [-o|--option_åèä] [--] <argument_åèä> + descriptor:åèä -o|--option_name <argument_name> + descriptor:åèä <argument_name> + + command åèä description + command åèä help + + + + + + + + + + From 07d206f22cc6cc41f58e9f61d649ce2ffa12092d Mon Sep 17 00:00:00 2001 From: Maxime STEINHAUSSER Date: Tue, 13 Dec 2016 15:52:36 +0100 Subject: [PATCH 2/2] Do not add fixtures for non relevant Json & Xml descriptors --- .../Descriptor/AbstractDescriptorTest.php | 2 +- .../Descriptor/MarkdownDescriptorTest.php | 18 ++ .../Tests/Descriptor/ObjectsProvider.php | 4 - .../Tests/Descriptor/TextDescriptorTest.php | 18 ++ .../Tests/Fixtures/application_mbstring.json | 273 ------------------ .../Tests/Fixtures/application_mbstring.xml | 154 ---------- .../Tests/Fixtures/command_mbstring.json | 32 -- .../Tests/Fixtures/command_mbstring.xml | 21 -- 8 files changed, 37 insertions(+), 485 deletions(-) delete mode 100644 src/Symfony/Component/Console/Tests/Fixtures/application_mbstring.json delete mode 100644 src/Symfony/Component/Console/Tests/Fixtures/application_mbstring.xml delete mode 100644 src/Symfony/Component/Console/Tests/Fixtures/command_mbstring.json delete mode 100644 src/Symfony/Component/Console/Tests/Fixtures/command_mbstring.xml diff --git a/src/Symfony/Component/Console/Tests/Descriptor/AbstractDescriptorTest.php b/src/Symfony/Component/Console/Tests/Descriptor/AbstractDescriptorTest.php index c36c4a8e5e8b9..74e95b7569977 100644 --- a/src/Symfony/Component/Console/Tests/Descriptor/AbstractDescriptorTest.php +++ b/src/Symfony/Component/Console/Tests/Descriptor/AbstractDescriptorTest.php @@ -86,7 +86,7 @@ abstract protected function getDescriptor(); abstract protected function getFormat(); - private function getDescriptionTestData(array $objects) + protected function getDescriptionTestData(array $objects) { $data = array(); foreach ($objects as $name => $object) { diff --git a/src/Symfony/Component/Console/Tests/Descriptor/MarkdownDescriptorTest.php b/src/Symfony/Component/Console/Tests/Descriptor/MarkdownDescriptorTest.php index c85e8a594beae..eb80f58b1cc58 100644 --- a/src/Symfony/Component/Console/Tests/Descriptor/MarkdownDescriptorTest.php +++ b/src/Symfony/Component/Console/Tests/Descriptor/MarkdownDescriptorTest.php @@ -12,9 +12,27 @@ namespace Symfony\Component\Console\Tests\Descriptor; use Symfony\Component\Console\Descriptor\MarkdownDescriptor; +use Symfony\Component\Console\Tests\Fixtures\DescriptorApplicationMbString; +use Symfony\Component\Console\Tests\Fixtures\DescriptorCommandMbString; class MarkdownDescriptorTest extends AbstractDescriptorTest { + public function getDescribeCommandTestData() + { + return $this->getDescriptionTestData(array_merge( + ObjectsProvider::getCommands(), + array('command_mbstring' => new DescriptorCommandMbString()) + )); + } + + public function getDescribeApplicationTestData() + { + return $this->getDescriptionTestData(array_merge( + ObjectsProvider::getApplications(), + array('application_mbstring' => new DescriptorApplicationMbString()) + )); + } + protected function getDescriptor() { return new MarkdownDescriptor(); diff --git a/src/Symfony/Component/Console/Tests/Descriptor/ObjectsProvider.php b/src/Symfony/Component/Console/Tests/Descriptor/ObjectsProvider.php index 26ea7602e6953..45b3b2fff9034 100644 --- a/src/Symfony/Component/Console/Tests/Descriptor/ObjectsProvider.php +++ b/src/Symfony/Component/Console/Tests/Descriptor/ObjectsProvider.php @@ -16,10 +16,8 @@ use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Tests\Fixtures\DescriptorApplication1; use Symfony\Component\Console\Tests\Fixtures\DescriptorApplication2; -use Symfony\Component\Console\Tests\Fixtures\DescriptorApplicationMbString; use Symfony\Component\Console\Tests\Fixtures\DescriptorCommand1; use Symfony\Component\Console\Tests\Fixtures\DescriptorCommand2; -use Symfony\Component\Console\Tests\Fixtures\DescriptorCommandMbString; /** * @author Jean-François Simon @@ -66,7 +64,6 @@ public static function getCommands() return array( 'command_1' => new DescriptorCommand1(), 'command_2' => new DescriptorCommand2(), - 'command_mbstring' => new DescriptorCommandMbString(), ); } @@ -75,7 +72,6 @@ public static function getApplications() return array( 'application_1' => new DescriptorApplication1(), 'application_2' => new DescriptorApplication2(), - 'application_mbstring' => new DescriptorApplicationMbString(), ); } } diff --git a/src/Symfony/Component/Console/Tests/Descriptor/TextDescriptorTest.php b/src/Symfony/Component/Console/Tests/Descriptor/TextDescriptorTest.php index 350b67950d2b1..364e29c02664b 100644 --- a/src/Symfony/Component/Console/Tests/Descriptor/TextDescriptorTest.php +++ b/src/Symfony/Component/Console/Tests/Descriptor/TextDescriptorTest.php @@ -12,9 +12,27 @@ namespace Symfony\Component\Console\Tests\Descriptor; use Symfony\Component\Console\Descriptor\TextDescriptor; +use Symfony\Component\Console\Tests\Fixtures\DescriptorApplicationMbString; +use Symfony\Component\Console\Tests\Fixtures\DescriptorCommandMbString; class TextDescriptorTest extends AbstractDescriptorTest { + public function getDescribeCommandTestData() + { + return $this->getDescriptionTestData(array_merge( + ObjectsProvider::getCommands(), + array('command_mbstring' => new DescriptorCommandMbString()) + )); + } + + public function getDescribeApplicationTestData() + { + return $this->getDescriptionTestData(array_merge( + ObjectsProvider::getApplications(), + array('application_mbstring' => new DescriptorApplicationMbString()) + )); + } + protected function getDescriptor() { return new TextDescriptor(); diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_mbstring.json b/src/Symfony/Component/Console/Tests/Fixtures/application_mbstring.json deleted file mode 100644 index 81c668395b045..0000000000000 --- a/src/Symfony/Component/Console/Tests/Fixtures/application_mbstring.json +++ /dev/null @@ -1,273 +0,0 @@ -{ - "commands": [ - { - "name": "help", - "usage": [ - "help [--xml] [--format FORMAT] [--raw] [--] []" - ], - "description": "Displays help for a command", - "help": "The help<\/info> command displays help for a given command:\n\n php app\/console help list<\/info>\n\nYou can also output the help in other formats by using the --format<\/comment> option:\n\n php app\/console help --format=xml list<\/info>\n\nTo display the list of available commands, please use the list<\/info> command.", - "definition": { - "arguments": { - "command_name": { - "name": "command_name", - "is_required": false, - "is_array": false, - "description": "The command name", - "default": "help" - } - }, - "options": { - "xml": { - "name": "--xml", - "shortcut": "", - "accept_value": false, - "is_value_required": false, - "is_multiple": false, - "description": "To output help as XML", - "default": false - }, - "format": { - "name": "--format", - "shortcut": "", - "accept_value": true, - "is_value_required": true, - "is_multiple": false, - "description": "The output format (txt, xml, json, or md)", - "default": "txt" - }, - "raw": { - "name": "--raw", - "shortcut": "", - "accept_value": false, - "is_value_required": false, - "is_multiple": false, - "description": "To output raw command help", - "default": false - }, - "help": { - "name": "--help", - "shortcut": "-h", - "accept_value": false, - "is_value_required": false, - "is_multiple": false, - "description": "Display this help message", - "default": false - }, - "quiet": { - "name": "--quiet", - "shortcut": "-q", - "accept_value": false, - "is_value_required": false, - "is_multiple": false, - "description": "Do not output any message", - "default": false - }, - "verbose": { - "name": "--verbose", - "shortcut": "-v|-vv|-vvv", - "accept_value": false, - "is_value_required": false, - "is_multiple": false, - "description": "Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug", - "default": false - }, - "version": { - "name": "--version", - "shortcut": "-V", - "accept_value": false, - "is_value_required": false, - "is_multiple": false, - "description": "Display this application version", - "default": false - }, - "ansi": { - "name": "--ansi", - "shortcut": "", - "accept_value": false, - "is_value_required": false, - "is_multiple": false, - "description": "Force ANSI output", - "default": false - }, - "no-ansi": { - "name": "--no-ansi", - "shortcut": "", - "accept_value": false, - "is_value_required": false, - "is_multiple": false, - "description": "Disable ANSI output", - "default": false - }, - "no-interaction": { - "name": "--no-interaction", - "shortcut": "-n", - "accept_value": false, - "is_value_required": false, - "is_multiple": false, - "description": "Do not ask any interactive question", - "default": false - } - } - } - }, - { - "name": "list", - "usage": [ - "list [--xml] [--raw] [--format FORMAT] [--] []" - ], - "description": "Lists commands", - "help": "The list<\/info> command lists all commands:\n\n php app\/console list<\/info>\n\nYou can also display the commands for a specific namespace:\n\n php app\/console list test<\/info>\n\nYou can also output the information in other formats by using the --format<\/comment> option:\n\n php app\/console list --format=xml<\/info>\n\nIt's also possible to get raw list of commands (useful for embedding command runner):\n\n php app\/console list --raw<\/info>", - "definition": { - "arguments": { - "namespace": { - "name": "namespace", - "is_required": false, - "is_array": false, - "description": "The namespace name", - "default": null - } - }, - "options": { - "xml": { - "name": "--xml", - "shortcut": "", - "accept_value": false, - "is_value_required": false, - "is_multiple": false, - "description": "To output list as XML", - "default": false - }, - "raw": { - "name": "--raw", - "shortcut": "", - "accept_value": false, - "is_value_required": false, - "is_multiple": false, - "description": "To output raw command list", - "default": false - }, - "format": { - "name": "--format", - "shortcut": "", - "accept_value": true, - "is_value_required": true, - "is_multiple": false, - "description": "The output format (txt, xml, json, or md)", - "default": "txt" - } - } - } - }, - { - "name": "descriptor:\u00e5\u00e8\u00e4", - "usage": [ - "descriptor:\u00e5\u00e8\u00e4 [-o|--option_\u00e5\u00e8\u00e4] [--] ", - "descriptor:\u00e5\u00e8\u00e4 -o|--option_name ", - "descriptor:\u00e5\u00e8\u00e4 " - ], - "description": "command \u00e5\u00e8\u00e4 description", - "help": "command \u00e5\u00e8\u00e4 help", - "definition": { - "arguments": { - "argument_\u00e5\u00e8\u00e4": { - "name": "argument_\u00e5\u00e8\u00e4", - "is_required": true, - "is_array": false, - "description": "", - "default": null - } - }, - "options": { - "option_\u00e5\u00e8\u00e4": { - "name": "--option_\u00e5\u00e8\u00e4", - "shortcut": "-o", - "accept_value": false, - "is_value_required": false, - "is_multiple": false, - "description": "", - "default": false - }, - "help": { - "name": "--help", - "shortcut": "-h", - "accept_value": false, - "is_value_required": false, - "is_multiple": false, - "description": "Display this help message", - "default": false - }, - "quiet": { - "name": "--quiet", - "shortcut": "-q", - "accept_value": false, - "is_value_required": false, - "is_multiple": false, - "description": "Do not output any message", - "default": false - }, - "verbose": { - "name": "--verbose", - "shortcut": "-v|-vv|-vvv", - "accept_value": false, - "is_value_required": false, - "is_multiple": false, - "description": "Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug", - "default": false - }, - "version": { - "name": "--version", - "shortcut": "-V", - "accept_value": false, - "is_value_required": false, - "is_multiple": false, - "description": "Display this application version", - "default": false - }, - "ansi": { - "name": "--ansi", - "shortcut": "", - "accept_value": false, - "is_value_required": false, - "is_multiple": false, - "description": "Force ANSI output", - "default": false - }, - "no-ansi": { - "name": "--no-ansi", - "shortcut": "", - "accept_value": false, - "is_value_required": false, - "is_multiple": false, - "description": "Disable ANSI output", - "default": false - }, - "no-interaction": { - "name": "--no-interaction", - "shortcut": "-n", - "accept_value": false, - "is_value_required": false, - "is_multiple": false, - "description": "Do not ask any interactive question", - "default": false - } - } - } - } - ], - "namespaces": [ - { - "id": "_global", - "commands": [ - "help", - "list" - ] - }, - { - "id": "descriptor", - "commands": [ - "descriptor:\u00e5\u00e8\u00e4" - ] - } - ] -} diff --git a/src/Symfony/Component/Console/Tests/Fixtures/application_mbstring.xml b/src/Symfony/Component/Console/Tests/Fixtures/application_mbstring.xml deleted file mode 100644 index e513d624876e7..0000000000000 --- a/src/Symfony/Component/Console/Tests/Fixtures/application_mbstring.xml +++ /dev/null @@ -1,154 +0,0 @@ - - - - - - help [--xml] [--format FORMAT] [--raw] [--] [<command_name>] - - Displays help for a command - The <info>help</info> command displays help for a given command: - - <info>php app/console help list</info> - - You can also output the help in other formats by using the <comment>--format</comment> option: - - <info>php app/console help --format=xml list</info> - - To display the list of available commands, please use the <info>list</info> command. - - - The command name - - help - - - - - - - - - - - - - - - - - - - list [--xml] [--raw] [--format FORMAT] [--] [<namespace>] - - Lists commands - The <info>list</info> command lists all commands: - - <info>php app/console list</info> - - You can also display the commands for a specific namespace: - - <info>php app/console list test</info> - - You can also output the information in other formats by using the <comment>--format</comment> option: - - <info>php app/console list --format=xml</info> - - It's also possible to get raw list of commands (useful for embedding command runner): - - <info>php app/console list --raw</info> - - - The namespace name - - - - - - - - - - - - descriptor:åèä [-o|--option_åèä] [--] <argument_åèä> - descriptor:åèä -o|--option_name <argument_name> - descriptor:åèä <argument_name> - - command åèä description - command åèä help - - - - - - - - - - - - - - - - - - - - - help - list - - - descriptor:åèä - - - diff --git a/src/Symfony/Component/Console/Tests/Fixtures/command_mbstring.json b/src/Symfony/Component/Console/Tests/Fixtures/command_mbstring.json deleted file mode 100644 index 5b8998971af97..0000000000000 --- a/src/Symfony/Component/Console/Tests/Fixtures/command_mbstring.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "name": "descriptor:\u00e5\u00e8\u00e4", - "usage": [ - "descriptor:\u00e5\u00e8\u00e4 [-o|--option_\u00e5\u00e8\u00e4] [--] ", - "descriptor:\u00e5\u00e8\u00e4 -o|--option_name ", - "descriptor:\u00e5\u00e8\u00e4 " - ], - "description": "command \u00e5\u00e8\u00e4 description", - "help": "command \u00e5\u00e8\u00e4 help", - "definition": { - "arguments": { - "argument_\u00e5\u00e8\u00e4": { - "name": "argument_\u00e5\u00e8\u00e4", - "is_required": true, - "is_array": false, - "description": "", - "default": null - } - }, - "options": { - "option_\u00e5\u00e8\u00e4": { - "name": "--option_\u00e5\u00e8\u00e4", - "shortcut": "-o", - "accept_value": false, - "is_value_required": false, - "is_multiple": false, - "description": "", - "default": false - } - } - } -} diff --git a/src/Symfony/Component/Console/Tests/Fixtures/command_mbstring.xml b/src/Symfony/Component/Console/Tests/Fixtures/command_mbstring.xml deleted file mode 100644 index e9f1a750692b6..0000000000000 --- a/src/Symfony/Component/Console/Tests/Fixtures/command_mbstring.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - descriptor:åèä [-o|--option_åèä] [--] <argument_åèä> - descriptor:åèä -o|--option_name <argument_name> - descriptor:åèä <argument_name> - - command åèä description - command åèä help - - - - - - - - - -