[Console] Fix wrong handling of multiline arg/opt descriptions

This commit is contained in:
Maxime Steinhausser 2016-11-30 19:19:43 +01:00
parent c360a222ef
commit 18fc6b54da
3 changed files with 10 additions and 10 deletions

View File

@ -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(' <info>%s</info>%s%s%s',
$this->writeText(sprintf(' <info>%s</info> %s%s%s',
$argument->getName(),
str_repeat(' ', $spacingWidth),
// + 17 = 2 spaces + <info> + </info> + 2 spaces
preg_replace('/\s*[\r\n]\s*/', "\n".str_repeat(' ', $totalWidth + 17), $argument->getDescription()),
// + 4 = 2 spaces before <info>, 2 spaces after </info>
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(' <info>%s</info>%s%s%s%s',
$this->writeText(sprintf(' <info>%s</info> %s%s%s%s',
$synopsis,
str_repeat(' ', $spacingWidth),
// + 17 = 2 spaces + <info> + </info> + 2 spaces
preg_replace('/\s*[\r\n]\s*/', "\n".str_repeat(' ', $totalWidth + 17), $option->getDescription()),
// + 4 = 2 spaces before <info>, 2 spaces after </info>
preg_replace('/\s*[\r\n]\s*/', "\n".str_repeat(' ', $totalWidth + 4), $option->getDescription()),
$default,
$option->isArray() ? '<comment> (multiple values allowed)</comment>' : ''
), $options);

View File

@ -1,2 +1,2 @@
<info>argument_name</info> multiline
argument description
argument description

View File

@ -1,2 +1,2 @@
<info>-o, --option_name=OPTION_NAME</info> multiline
option description
option description