From 18fc6b54da0108cb0393142066affa005c99e88b Mon Sep 17 00:00:00 2001 From: Maxime Steinhausser Date: Wed, 30 Nov 2016 19:19:43 +0100 Subject: [PATCH] [Console] Fix wrong handling of multiline arg/opt descriptions --- .../Console/Descriptor/TextDescriptor.php | 16 ++++++++-------- .../Console/Tests/Fixtures/input_argument_4.txt | 2 +- .../Console/Tests/Fixtures/input_option_5.txt | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Symfony/Component/Console/Descriptor/TextDescriptor.php b/src/Symfony/Component/Console/Descriptor/TextDescriptor.php index 0d722ed5aa..eb02c89dfa 100644 --- a/src/Symfony/Component/Console/Descriptor/TextDescriptor.php +++ b/src/Symfony/Component/Console/Descriptor/TextDescriptor.php @@ -38,13 +38,13 @@ class TextDescriptor extends Descriptor } $totalWidth = isset($options['total_width']) ? $options['total_width'] : strlen($argument->getName()); - $spacingWidth = $totalWidth - strlen($argument->getName()) + 2; + $spacingWidth = $totalWidth - strlen($argument->getName()); - $this->writeText(sprintf(' %s%s%s%s', + $this->writeText(sprintf(' %s %s%s%s', $argument->getName(), str_repeat(' ', $spacingWidth), - // + 17 = 2 spaces + + + 2 spaces - preg_replace('/\s*[\r\n]\s*/', "\n".str_repeat(' ', $totalWidth + 17), $argument->getDescription()), + // + 4 = 2 spaces before , 2 spaces after + preg_replace('/\s*[\r\n]\s*/', "\n".str_repeat(' ', $totalWidth + 4), $argument->getDescription()), $default ), $options); } @@ -75,13 +75,13 @@ class TextDescriptor extends Descriptor sprintf('--%s%s', $option->getName(), $value) ); - $spacingWidth = $totalWidth - strlen($synopsis) + 2; + $spacingWidth = $totalWidth - strlen($synopsis); - $this->writeText(sprintf(' %s%s%s%s%s', + $this->writeText(sprintf(' %s %s%s%s%s', $synopsis, str_repeat(' ', $spacingWidth), - // + 17 = 2 spaces + + + 2 spaces - preg_replace('/\s*[\r\n]\s*/', "\n".str_repeat(' ', $totalWidth + 17), $option->getDescription()), + // + 4 = 2 spaces before , 2 spaces after + preg_replace('/\s*[\r\n]\s*/', "\n".str_repeat(' ', $totalWidth + 4), $option->getDescription()), $default, $option->isArray() ? ' (multiple values allowed)' : '' ), $options); diff --git a/src/Symfony/Component/Console/Tests/Fixtures/input_argument_4.txt b/src/Symfony/Component/Console/Tests/Fixtures/input_argument_4.txt index aa74e8ceb2..fc7d669a11 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/input_argument_4.txt +++ b/src/Symfony/Component/Console/Tests/Fixtures/input_argument_4.txt @@ -1,2 +1,2 @@ argument_name multiline - argument description + argument description diff --git a/src/Symfony/Component/Console/Tests/Fixtures/input_option_5.txt b/src/Symfony/Component/Console/Tests/Fixtures/input_option_5.txt index 4368883cc7..9563b4cab1 100644 --- a/src/Symfony/Component/Console/Tests/Fixtures/input_option_5.txt +++ b/src/Symfony/Component/Console/Tests/Fixtures/input_option_5.txt @@ -1,2 +1,2 @@ -o, --option_name=OPTION_NAME multiline - option description + option description