style: enhance help and list commands using TableAdapter
Some checks failed
CI / tasker (8.2) (push) Has been cancelled
CI / tasker (8.3) (push) Has been cancelled

This commit is contained in:
Funky Waddle 2026-02-22 04:02:32 -06:00
parent 3ac2894fd8
commit 77538a7966
2 changed files with 18 additions and 4 deletions

View file

@ -4,10 +4,11 @@ declare(strict_types=1);
namespace Phred\Tasker\Commands; namespace Phred\Tasker\Commands;
use Phred\Tasker\Runner;
use Phred\ConsoleContracts\CommandInterface; use Phred\ConsoleContracts\CommandInterface;
use Phred\ConsoleContracts\InputInterface; use Phred\ConsoleContracts\InputInterface;
use Phred\ConsoleContracts\OutputInterface; use Phred\ConsoleContracts\OutputInterface;
use Phred\Tasker\Runner;
use Phred\TaskerBridges\Phred\TableAdapter;
class HelpCommand implements CommandInterface class HelpCommand implements CommandInterface
{ {
@ -70,18 +71,22 @@ class HelpCommand implements CommandInterface
$arguments = $command->getArguments(); $arguments = $command->getArguments();
if ($arguments) { if ($arguments) {
$output->writeln('<info>Arguments:</info>'); $output->writeln('<info>Arguments:</info>');
$table = new TableAdapter($output);
foreach ($arguments as $name => $desc) { foreach ($arguments as $name => $desc) {
$output->writeln(sprintf(' <success>%s</success> %s', str_pad($name, 20), $desc)); $table->addRow(["<success>{$name}</success>", $desc]);
} }
$table->render();
$output->writeln(''); $output->writeln('');
} }
$options = $command->getOptions(); $options = $command->getOptions();
if ($options) { if ($options) {
$output->writeln('<info>Options:</info>'); $output->writeln('<info>Options:</info>');
$table = new TableAdapter($output);
foreach ($options as $name => $desc) { foreach ($options as $name => $desc) {
$output->writeln(sprintf(' <success>%s</success> %s', str_pad($name, 20), $desc)); $table->addRow(["<success>{$name}</success>", $desc]);
} }
$table->render();
$output->writeln(''); $output->writeln('');
} }

View file

@ -8,6 +8,7 @@ use Phred\ConsoleContracts\CommandInterface;
use Phred\ConsoleContracts\InputInterface; use Phred\ConsoleContracts\InputInterface;
use Phred\ConsoleContracts\OutputInterface; use Phred\ConsoleContracts\OutputInterface;
use Phred\Tasker\Runner; use Phred\Tasker\Runner;
use Phred\TaskerBridges\Phred\TableAdapter;
class ListCommand implements CommandInterface class ListCommand implements CommandInterface
{ {
@ -47,10 +48,18 @@ class ListCommand implements CommandInterface
$commands = $this->runner->getCommands(); $commands = $this->runner->getCommands();
ksort($commands); ksort($commands);
$table = new TableAdapter($output);
$table->setHeaders(['Command', 'Description']);
foreach ($commands as $name => $command) { foreach ($commands as $name => $command) {
$output->writeln(sprintf(' <success>%s</success> %s', str_pad($name, 20), $command->getDescription())); $table->addRow([
"<success>{$name}</success>",
$command->getDescription()
]);
} }
$table->render();
return 0; return 0;
} }
} }