Skip to content

Commit b5fecc1

Browse files
committed
feat: update command list renderer
1 parent c62eb9f commit b5fecc1

File tree

1 file changed

+33
-7
lines changed

1 file changed

+33
-7
lines changed

src/Sprout/App.php

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -280,27 +280,53 @@ protected function parseSignatureTokens(array $input)
280280

281281
protected function renderListView()
282282
{
283-
$commandList = '';
283+
$groups = [];
284284

285285
foreach ($this->config['commands'] as $commandName => $command) {
286-
$commandList .= " \033[1;32m$commandName\033[0m — {$command['handler']->getDescription()}\n";
286+
$parts = explode(':', $commandName, 2);
287+
288+
$namespace = (count($parts) === 2) ? $parts[0] : '_global';
289+
290+
$groups[$namespace][$commandName] = $command['handler']->getDescription();
287291
}
288292

289-
echo <<<HELP
293+
ksort($groups);
294+
295+
foreach ($groups as $namespace => &$commands) {
296+
ksort($commands);
297+
}
298+
299+
$output = <<<HELP
290300
{$this->config['name']} {$this->config['version']}
291301
292302
Usage:
293303
command [options] [arguments]
294304
295305
Options:
296-
-h, --help - Display help for the given command.
297-
-V, --version - Display this application version
306+
-h, --help Display help for the given command
307+
-V, --version Display this application version
298308
299309
Available commands:
300-
\033[1;32mlist\033[0m — List commands
301-
$commandList
302310
303311
HELP;
312+
313+
if (isset($groups['_global'])) {
314+
foreach ($groups['_global'] as $name => $desc) {
315+
$output .= sprintf(" \033[1;32m%-18s\033[0m %s\n", $name, $desc);
316+
}
317+
318+
unset($groups['_global']);
319+
}
320+
321+
foreach ($groups as $namespace => $commands) {
322+
$output .= " $namespace\n";
323+
324+
foreach ($commands as $name => $desc) {
325+
$output .= sprintf(" \033[1;32m%-18s\033[0m %s\n", $name, $desc);
326+
}
327+
}
328+
329+
echo Style\Renderer::render($output);
304330
}
305331

306332
protected function renderHelpView(Command $command)

0 commit comments

Comments
 (0)