/** * Execute console. * * @param AbstractInput $input * @param Output $output */ protected function execute(AbstractInput $input, Output $output) { $output->writeln($this->getApplication()->getApplicationVersion()); $output->write("\n"); $names = $this->getConsoles(); $width = $output->getMaxWidth($names) + 4; $output->writeln(sprintf('<style name="comment">%s</style>', 'Available commands:')); foreach ($names as $name) { $description = null; $cleanName = strip_tags(trim($name)); if ($this->application->hasConsole($cleanName)) { $description = $this->application->getConsole($cleanName)->getDescription(); } $output->writeln($output->width($width, $name) . ' ' . (string) $description); } }
/** * Execute console. * * @param AbstractInput $input * @param Output $output */ protected function execute(AbstractInput $input, Output $output) { $name = $input->argument->get('console_name'); $console = $this->application->getConsole($name); $arguments = $this->buildArguments($console); $options = $this->buildOptions($console); $width = $output->getMaxWidth(array_merge($arguments, $options)); $output->writeln(sprintf('<style name="comment">%s</style>', 'Usage:')); $output->writeln($this->buildUsage($console)); $this->writeArguments($arguments, $width, $console, $output); $this->writeOptions($options, $width, $console, $output); if ($help = $console->getHelp()) { $output->writeln(); $output->writeln(sprintf('<style name="comment">%s</style>', 'Help:')); $output->writeln(' ' . $help); } }
/** * Compute max width. * * @return int[] */ private function computeMaxWidth() { $widths = array(); foreach ($this->headers as $header) { $widths[] = strlen($header->getClean()) + 2; } foreach ($this->rows as $row) { foreach ($row as $index => $cell) { $cells = $this->collectCell($index); $width = $this->output->getMaxWidth($this->normalizeContent($cells)) + 2; if (!isset($widths[$index]) || $widths[$index] < $width) { $widths[$index] = $width; } } } return $widths; }