You are here

protected function TextDescriptor::describeApplication in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/symfony/console/Descriptor/TextDescriptor.php \Symfony\Component\Console\Descriptor\TextDescriptor::describeApplication()

Describes an Application instance.

Parameters

Application $application:

array $options:

Return value

string|mixed

Overrides Descriptor::describeApplication

File

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

Class

TextDescriptor
Text descriptor.

Namespace

Symfony\Component\Console\Descriptor

Code

protected function describeApplication(Application $application, array $options = array()) {
  $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 {
    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");
    $width = $this
      ->getColumnWidth($description
      ->getCommands());
    if ($describedNamespace) {
      $this
        ->writeText(sprintf('<comment>Available commands for the "%s" namespace:</comment>', $describedNamespace), $options);
    }
    else {
      $this
        ->writeText('<comment>Available commands:</comment>', $options);
    }

    // add commands by namespace
    foreach ($description
      ->getNamespaces() as $namespace) {
      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 - strlen($name);
        $this
          ->writeText(sprintf('  <info>%s</info>%s%s', $name, str_repeat(' ', $spacingWidth), $description
          ->getCommand($name)
          ->getDescription()), $options);
      }
    }
    $this
      ->writeText("\n");
  }
}