diff --git a/src/Symfony/Component/Console/Descriptor/MarkdownDescriptor.php b/src/Symfony/Component/Console/Descriptor/MarkdownDescriptor.php index 2eb9944d62..c2d6243e28 100644 --- a/src/Symfony/Component/Console/Descriptor/MarkdownDescriptor.php +++ b/src/Symfony/Component/Console/Descriptor/MarkdownDescriptor.php @@ -13,6 +13,7 @@ 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; @@ -94,7 +95,7 @@ class MarkdownDescriptor extends Descriptor $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 @@ class MarkdownDescriptor extends Descriptor $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 eb02c89dfa..c18ed6f224 100644 --- a/src/Symfony/Component/Console/Descriptor/TextDescriptor.php +++ b/src/Symfony/Component/Console/Descriptor/TextDescriptor.php @@ -13,6 +13,7 @@ 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; @@ -37,7 +38,7 @@ class TextDescriptor extends Descriptor $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 @@ class TextDescriptor extends Descriptor 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 @@ class TextDescriptor extends Descriptor { $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 @@ class TextDescriptor extends Descriptor 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 @@ class TextDescriptor extends Descriptor $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 @@ class TextDescriptor extends Descriptor $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/AbstractDescriptorTest.php b/src/Symfony/Component/Console/Tests/Descriptor/AbstractDescriptorTest.php index c36c4a8e5e..74e95b7569 100644 --- a/src/Symfony/Component/Console/Tests/Descriptor/AbstractDescriptorTest.php +++ b/src/Symfony/Component/Console/Tests/Descriptor/AbstractDescriptorTest.php @@ -86,7 +86,7 @@ abstract class AbstractDescriptorTest extends \PHPUnit_Framework_TestCase 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 c85e8a594b..eb80f58b1c 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/TextDescriptorTest.php b/src/Symfony/Component/Console/Tests/Descriptor/TextDescriptorTest.php index 350b67950d..364e29c026 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/DescriptorApplicationMbString.php b/src/Symfony/Component/Console/Tests/Fixtures/DescriptorApplicationMbString.php new file mode 100644 index 0000000000..bf170c449f --- /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 0000000000..66de917e29 --- /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.md b/src/Symfony/Component/Console/Tests/Fixtures/application_mbstring.md new file mode 100644 index 0000000000..ef81f86972 --- /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 0000000000..9d21f829d5 --- /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/command_mbstring.md b/src/Symfony/Component/Console/Tests/Fixtures/command_mbstring.md new file mode 100644 index 0000000000..2adac53f05 --- /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 0000000000..969a065242 --- /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