8000 different approach · symfony/symfony@1459492 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1459492

Browse files
committed
different approach
1 parent 72374eb commit 1459492

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

src/Symfony/Component/Console/Descriptor/TextDescriptor.php

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,8 @@ protected function describeApplication(Application $application, array $options
198198
$commands[$name] = $description->getCommand($name);
199199
}
200200
}
201+
202+
// calculate max. width based on available commands per namespace
201203
$width = $this->getColumnWidth(call_user_func_array('array_merge', array_map(function ($namespace) use ($commands) {
202204
return array_intersect($namespace['commands'], array_keys($commands));
203205
}, $namespaces)));
@@ -209,19 +211,25 @@ protected function describeApplication(Application $application, array $options
209211
}
210212

211213
foreach ($namespaces as $namespace) {
212-
if (!$describedNamespace && ApplicationDescription::GLOBAL_NAMESPACE !== $namespace['id'] && array_intersect($namespace['commands'], array_keys($commands))) {
214+
$namespace['commands'] = array_filter($namespace['commands'], function ($name) use ($commands) {
215+
return isset($commands[$name]);
216+
});
217+
218+
if (!$namespace['commands']) {
219+
continue;
220+
}
221+
222+
if (!$describedNamespace && ApplicationDescription::GLOBAL_NAMESPACE !== $namespace['id']) {
213223
$this->writeText("\n");
214224
$this->writeText(' <comment>'.$namespace['id'].'</comment>', $options);
215225
}
216226

217227
foreach ($namespace['commands'] as $name) {
218-
if (isset($commands[$name])) {
219-
$this->writeText("\n");
220-
$spacingWidth = $width - strlen($name);
221-
$command = $commands[$name];
222-
$commandAliases = $name === $command->getName() ? $this->getCommandAliasesText($command) : '';
223-
$this->writeText(sprintf(' <info>%s</info>%s%s', $name, str_repeat(' ', $spacingWidth), $commandAliases.$command->getDescription()), $options);
224-
}
228+
$this->writeText("\n");
229+
$spacingWidth = $width - strlen($name);
230+
$command = $commands[$name];
231+
$commandAliases = $name === $command->getName() ? $this->getCommandAliasesText($command) : '';
232+
$this->writeText(sprintf(' <info>%s</info>%s%s', $name, str_repeat(' ', $spacingWidth), $commandAliases.$command->getDescription()), $options);
225233
}
226234
}
227235

0 commit comments

Comments
 (0)
0