protected function describeApplication(ConsoleApplication $application, array $options = [])
{
$describedNamespace = isset($options['namespace']) ? $options['namespace'] : null;
$description = new ApplicationDescription($application, $describedNamespace);
if (isset($options['raw_text']) && $options['raw_text']) {
$width = $this->getColumnWidth($description->getCommands());
foreach ($description->getCommands() as $command) {
$this->writeText(sprintf("%-{$width}s %s", $command->getName(), $command->getDescription()), $options);
$this->writeText("\n");
}
} else {
$width = $this->getColumnWidth($description->getCommands());
$this->writeText($application->getHelp(), $options);
$this->writeText("\n\n");
if ($describedNamespace) {
$this->writeText(sprintf("<comment>Available commands for the \"%s\" namespace:</comment>", $describedNamespace), $options);
} else {
$this->writeText('<comment>Available commands:</comment>', $options);
}
// Display commands grouped by namespace.
foreach ($description->getNamespaces() as $namespace) {
// Filter hidden commands in the namespace.
/** @var Command[] $commands */
$commands = [];
foreach ($namespace['commands'] as $name) {
$command = $description->getCommand($name);
if ($command instanceof CanHideInListInterface && $command->isHiddenInList()) {
continue;
}
$commands[$name] = $command;
}
// Skip the namespace if it doesn't contain any commands.
if (!count($commands)) {
continue;
}
// Display the namespace name.
if (!$describedNamespace && ApplicationDescription::GLOBAL_NAMESPACE !== $namespace['id']) {
$this->writeText("\n");
$this->writeText('<comment>' . $namespace['id'] . '</comment>', $options);
}
// Display each command.
foreach ($commands as $name => $command) {
$aliases = $command->getAliases();
if ($aliases && in_array($name, $aliases)) {
// If the command is an alias, do not list it in the
// 'global' namespace. The aliases will be shown inline
// with the full command name.
continue;
}
if ($command instanceof CommandBase) {
$aliases = $command->getVisibleAliases();
}
// Colour local commands differently from remote ones.
$commandDescription = $command->getDescription();
if ($command instanceof CommandBase && !$command->isLocal()) {
$commandDescription = "<fg=cyan>{$commandDescription}</fg=cyan>";
}
$this->writeText("\n");
$this->writeText(sprintf(" %-{$width}s %s", "<info>{$name}</info>" . $this->formatAliases($aliases), $commandDescription), $options);
}
}
$this->writeText("\n");
}
}