Improves help command

This commit is contained in:
Nuno Maduro
2022-09-18 11:10:18 +01:00
parent 0e0e2adfbe
commit 4de7284657
3 changed files with 21 additions and 9 deletions

View File

@ -45,7 +45,7 @@ final class Help implements HandlesArguments
$this->output->writeln([
'',
sprintf(' <fg=blue;options=bold>%s:</>', mb_strtoupper($title)),
sprintf(' <fg=yellow;options=bold>%s OPTIONS:</>', mb_strtoupper($title)),
]);
foreach ($options as $option) {
@ -58,6 +58,8 @@ final class Help implements HandlesArguments
'desc' => $description,
] = $option;
$argument = $this->colorizeOptions($argument);
View::render('components.two-column-detail', [
'left' => $argument,
'right' => $description,
@ -73,6 +75,16 @@ final class Help implements HandlesArguments
return $arguments;
}
/**
* Colorizes the given string options.
*/
private function colorizeOptions(string $argument): string
{
$argument = (string) preg_replace('/(--\w+)/', '<fg=blue;options=bold>$1</>', $argument);
return (string) preg_replace('/(-\w+)/', '<fg=blue;options=bold>$1</>', $argument);
}
/**
* @return array<string, array<int, array{arg?: string, desc: string}>>
*/