12 namespace Symfony\Component\Console\Descriptor;
40 $totalWidth = isset($options[
'total_width']) ? $options[
'total_width'] : strlen($argument->
getName());
41 $spacingWidth = $totalWidth - strlen($argument->
getName()) + 2;
43 $this->
writeText(sprintf(
' <info>%s</info>%s%s%s',
45 str_repeat(
' ', $spacingWidth),
47 preg_replace(
'/\s*[\r\n]\s*/',
"\n".str_repeat(
' ', $totalWidth + 17), $argument->
getDescription()),
65 $value =
'='.strtoupper($option->
getName());
68 $value =
'['.$value.
']';
73 $synopsis = sprintf(
'%s%s',
75 sprintf(
'--%s%s', $option->
getName(), $value)
78 $spacingWidth = $totalWidth - strlen($synopsis) + 2;
80 $this->
writeText(sprintf(
' <info>%s</info>%s%s%s%s',
82 str_repeat(
' ', $spacingWidth),
84 preg_replace(
'/\s*[\r\n]\s*/',
"\n".str_repeat(
' ', $totalWidth + 17), $option->
getDescription()),
86 $option->
isArray() ?
'<comment> (multiple values allowed)</comment>' :
''
97 $totalWidth = max($totalWidth, strlen($argument->
getName()));
101 $this->
writeText(
'<comment>Arguments:</comment>', $options);
114 $laterOptions = array();
116 $this->
writeText(
'<comment>Options:</comment>', $options);
117 foreach ($definition->
getOptions() as $option) {
119 $laterOptions[] = $option;
123 $this->
describeInputOption($option, array_merge($options, array(
'total_width' => $totalWidth)));
125 foreach ($laterOptions as $option) {
127 $this->
describeInputOption($option, array_merge($options, array(
'total_width' => $totalWidth)));
141 $this->
writeText(
'<comment>Usage:</comment>', $options);
157 $this->
writeText(
'<comment>Help:</comment>', $options);
159 $this->
writeText(
' '.str_replace(
"\n",
"\n ", $help), $options);
169 $describedNamespace = isset($options[
'namespace']) ? $options[
'namespace'] : null;
172 if (isset($options[
'raw_text']) && $options[
'raw_text']) {
175 foreach ($description->getCommands() as $command) {
180 if (
'' != $help = $application->
getHelp()) {
184 $this->
writeText(
"<comment>Usage:</comment>\n", $options);
185 $this->
writeText(
" command [options] [arguments]\n\n", $options);
194 if ($describedNamespace) {
195 $this->
writeText(sprintf(
'<comment>Available commands for the "%s" namespace:</comment>', $describedNamespace), $options);
197 $this->
writeText(
'<comment>Available commands:</comment>', $options);
201 foreach ($description->getNamespaces() as $namespace) {
204 $this->
writeText(
' <comment>'.$namespace[
'id'].
'</comment>', $options);
207 foreach ($namespace[
'commands'] as $name) {
209 $spacingWidth = $width - strlen($name);
210 $this->
writeText(sprintf(
' <info>%s</info>%s%s', $name, str_repeat(
' ', $spacingWidth), $description->getCommand($name)->getDescription()), $options);
221 private function writeText($content, array $options = array())
224 isset($options[
'raw_text']) && $options[
'raw_text'] ? strip_tags($content) : $content,
225 isset($options[
'raw_output']) ? !$options[
'raw_output'] :
true
238 if (PHP_VERSION_ID < 50400) {
239 return str_replace(
'\/',
'/', json_encode($default));
242 return json_encode($default, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
254 foreach ($commands as $command) {
255 $widths[] = strlen($command->getName());
256 foreach ($command->getAliases() as $alias) {
257 $widths[] = strlen($alias);
261 return max($widths) + 2;
272 foreach ($options as $option) {
274 $nameLength = 1 + max(strlen($option->getShortcut()), 1) + 4 + strlen($option->getName());
276 if ($option->acceptValue()) {
277 $valueLength = 1 + strlen($option->getName());
278 $valueLength += $option->isValueOptional() ? 2 : 0;
280 $nameLength += $valueLength;
282 $totalWidth = max($totalWidth, $nameLength);