commands->getCommands(); $this->describeCommands($commands); CLI::newLine(); } //-------------------------------------------------------------------- /** * Displays the commands on the CLI. * * @param array $commands */ protected function describeCommands(array $commands = []) { ksort($commands); // Sort into buckets by group $sorted = []; $maxTitleLength = 0; foreach ($commands as $title => $command) { if (! isset($sorted[$command['group']])) { $sorted[$command['group']] = []; } $sorted[$command['group']][$title] = $command; $maxTitleLength = max($maxTitleLength, strlen($title)); } ksort($sorted); // Display it all... foreach ($sorted as $group => $items) { CLI::newLine(); CLI::write($group); foreach ($items as $title => $item) { $title = $this->padTitle($title, $maxTitleLength, 2, 2); $out = CLI::color($title, 'yellow'); if (isset($item['description'])) { $out .= CLI::wrap($item['description'], 125, strlen($title)); } CLI::write($out); } } } //-------------------------------------------------------------------- /** * Pads our string out so that all titles are the same length to nicely line up descriptions. * * @param string $item * @param integer $max * @param integer $extra // How many extra spaces to add at the end * @param integer $indent * * @return string */ protected function padTitle(string $item, int $max, int $extra = 2, int $indent = 0): string { $max += $extra + $indent; $item = str_repeat(' ', $indent) . $item; $item = str_pad($item, $max); return $item; } //-------------------------------------------------------------------- }