Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. TextDescriptor.php

function TextDescriptor::describeApplication

Overrides Descriptor::describeApplication

File

vendor/symfony/console/Descriptor/TextDescriptor.php, line 160

Class

TextDescriptor
Text descriptor.

Namespace

Symfony\Component\Console\Descriptor

Code

protected function describeApplication(Application $application, array $options = []) : void {
    $describedNamespace = $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 {
        if ('' != ($help = $application->getHelp())) {
            $this->writeText("{$help}\n\n", $options);
        }
        $this->writeText("<comment>Usage:</comment>\n", $options);
        $this->writeText("  command [options] [arguments]\n\n", $options);
        $this->describeInputDefinition(new InputDefinition($application->getDefinition()
            ->getOptions()), $options);
        $this->writeText("\n");
        $this->writeText("\n");
        $commands = $description->getCommands();
        $namespaces = $description->getNamespaces();
        if ($describedNamespace && $namespaces) {
            // make sure all alias commands are included when describing a specific namespace
            $describedNamespaceInfo = reset($namespaces);
            foreach ($describedNamespaceInfo['commands'] as $name) {
                $commands[$name] = $description->getCommand($name);
            }
        }
        // calculate max. width based on available commands per namespace
        $width = $this->getColumnWidth(array_merge(...array_values(array_map(fn($namespace) => array_intersect($namespace['commands'], array_keys($commands)), array_values($namespaces)))));
        if ($describedNamespace) {
            $this->writeText(\sprintf('<comment>Available commands for the "%s" namespace:</comment>', $describedNamespace), $options);
        }
        else {
            $this->writeText('<comment>Available commands:</comment>', $options);
        }
        foreach ($namespaces as $namespace) {
            $namespace['commands'] = array_filter($namespace['commands'], fn($name) => isset($commands[$name]));
            if (!$namespace['commands']) {
                continue;
            }
            if (!$describedNamespace && ApplicationDescription::GLOBAL_NAMESPACE !== $namespace['id']) {
                $this->writeText("\n");
                $this->writeText(' <comment>' . $namespace['id'] . '</comment>', $options);
            }
            foreach ($namespace['commands'] as $name) {
                $this->writeText("\n");
                $spacingWidth = $width - Helper::width($name);
                $command = $commands[$name];
                $commandAliases = $name === $command->getName() ? $this->getCommandAliasesText($command) : '';
                $this->writeText(\sprintf('  <info>%s</info>%s%s', $name, str_repeat(' ', $spacingWidth), $commandAliases . $command->getDescription()), $options);
            }
        }
        $this->writeText("\n");
    }
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal