Skip to content

Commit

Permalink
[Console] refactored definition printer
Browse files Browse the repository at this point in the history
  • Loading branch information
everzet committed Jul 6, 2011
1 parent e49d61f commit fa20b51
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions src/Symfony/Component/Console/Input/InputDefinition.php
Expand Up @@ -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;

Expand All @@ -426,7 +431,9 @@ public function asText()
$default = '';
}

$text[] = sprintf(" <info>%-${max}s</info> %s%s", $argument->getName(), $argument->getDescription(), $default);
$description = str_replace("\n", "\n".str_pad('', $max + 2, ' '), $argument->getDescription());

$text[] = sprintf(" <info>%-${max}s</info> %s%s", $argument->getName(), $description, $default);
}

$text[] = '';
Expand All @@ -443,7 +450,16 @@ public function asText()
}

$multiple = $option->isArray() ? '<comment> (multiple values allowed)</comment>' : '';
$text[] = sprintf(' %-'.$max.'s %s%s%s%s', '<info>--'.$option->getName().'</info>', $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(" <info>%s</info> %-${optionMax}s%s%s%s",
'--'.$option->getName(),
$option->getShortcut() ? sprintf('(-%s) ', $option->getShortcut()) : '',
$description,
$default,
$multiple
);
}

$text[] = '';
Expand Down

0 comments on commit fa20b51

Please sign in to comment.