/** * Build rows. * * @param array $widths */ private function buildRows(array $widths) { foreach ($this->rows as $row) { $this->writeBorders($widths); foreach ($row as $index => $cell) { $width = $widths[$index]; $this->output->write(sprintf('| %s ', $this->output->width($width - 2, (string) $cell))); } $this->output->writeln('|'); } }
/** * 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); } }
/** * Write list of options. * * @param array $options * @param int $width * @param AbstractConsole $console * @param Output $output */ private function writeOptions(array $options, $width, AbstractConsole $console, Output $output) { if (!empty($options)) { $output->writeln(); $output->writeln(sprintf('<style name="comment">%s</style>', 'Options:')); foreach ($options as $option) { $clean = trim(strip_tags($option)); $pos = strpos($clean, '--'); $parts = explode('=', substr($clean, $pos + 2)); $opt = $console->getDefinition()->getOption($parts[0]); $description = $opt->getDescription(); if (null !== ($default = $opt->getDefault())) { if ($description) { $description .= ' '; } $description .= sprintf('<style name="comment">[default: "%s"]</style>', $default); } $output->writeln($output->width($width, $option) . ' ' . $description); } } }