diff --git a/src/Symfony/Component/Console/Input/InputDefinition.php b/src/Symfony/Component/Console/Input/InputDefinition.php
index d5d0d0830844..02aff0312170 100644
--- a/src/Symfony/Component/Console/Input/InputDefinition.php
+++ b/src/Symfony/Component/Console/Input/InputDefinition.php
@@ -408,10 +408,15 @@ public function asText()
// find the largest option or argument name
$max = 0;
foreach ($this->getOptions() as $option) {
- $max = strlen($option->getName()) + 2 > $max ? strlen($option->getName()) + 2 : $max;
+ $nameLength = strlen($option->getName()) + 2;
+ if ($option->getShortcut()) {
+ $nameLength += strlen($option->getShortcut()) + 3;
+ }
+
+ $max = max($max, $nameLength);
}
foreach ($this->getArguments() as $argument) {
- $max = strlen($argument->getName()) > $max ? strlen($argument->getName()) : $max;
+ $max = max($max, strlen($argument->getName()));
}
++$max;
@@ -426,7 +431,9 @@ public function asText()
$default = '';
}
- $text[] = sprintf(" %-${max}s %s%s", $argument->getName(), $argument->getDescription(), $default);
+ $description = str_replace("\n", "\n".str_pad('', $max + 2, ' '), $argument->getDescription());
+
+ $text[] = sprintf(" %-${max}s %s%s", $argument->getName(), $description, $default);
}
$text[] = '';
@@ -443,7 +450,16 @@ public function asText()
}
$multiple = $option->isArray() ? ' (multiple values allowed)' : '';
- $text[] = sprintf(' %-'.$max.'s %s%s%s%s', '--'.$option->getName().'', $option->getShortcut() ? sprintf('(-%s) ', $option->getShortcut()) : '', $option->getDescription(), $default, $multiple);
+ $description = str_replace("\n", "\n".str_pad('', $max + 2, ' '), $option->getDescription());
+
+ $optionMax = $max - strlen($option->getName()) - 2;
+ $text[] = sprintf(" %s %-${optionMax}s%s%s%s",
+ '--'.$option->getName(),
+ $option->getShortcut() ? sprintf('(-%s) ', $option->getShortcut()) : '',
+ $description,
+ $default,
+ $multiple
+ );
}
$text[] = '';