From 77538a7966e6a096fc58987bdf86cc8a7f596b84 Mon Sep 17 00:00:00 2001 From: Funky Waddle Date: Sun, 22 Feb 2026 04:02:32 -0600 Subject: [PATCH] style: enhance help and list commands using TableAdapter --- src/Commands/HelpCommand.php | 11 ++++++++--- src/Commands/ListCommand.php | 11 ++++++++++- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/Commands/HelpCommand.php b/src/Commands/HelpCommand.php index 72b3dc8..268a9d2 100644 --- a/src/Commands/HelpCommand.php +++ b/src/Commands/HelpCommand.php @@ -4,10 +4,11 @@ declare(strict_types=1); namespace Phred\Tasker\Commands; -use Phred\Tasker\Runner; use Phred\ConsoleContracts\CommandInterface; use Phred\ConsoleContracts\InputInterface; use Phred\ConsoleContracts\OutputInterface; +use Phred\Tasker\Runner; +use Phred\TaskerBridges\Phred\TableAdapter; class HelpCommand implements CommandInterface { @@ -70,18 +71,22 @@ class HelpCommand implements CommandInterface $arguments = $command->getArguments(); if ($arguments) { $output->writeln('Arguments:'); + $table = new TableAdapter($output); foreach ($arguments as $name => $desc) { - $output->writeln(sprintf(' %s %s', str_pad($name, 20), $desc)); + $table->addRow(["{$name}", $desc]); } + $table->render(); $output->writeln(''); } $options = $command->getOptions(); if ($options) { $output->writeln('Options:'); + $table = new TableAdapter($output); foreach ($options as $name => $desc) { - $output->writeln(sprintf(' %s %s', str_pad($name, 20), $desc)); + $table->addRow(["{$name}", $desc]); } + $table->render(); $output->writeln(''); } diff --git a/src/Commands/ListCommand.php b/src/Commands/ListCommand.php index e9025e7..556906e 100644 --- a/src/Commands/ListCommand.php +++ b/src/Commands/ListCommand.php @@ -8,6 +8,7 @@ use Phred\ConsoleContracts\CommandInterface; use Phred\ConsoleContracts\InputInterface; use Phred\ConsoleContracts\OutputInterface; use Phred\Tasker\Runner; +use Phred\TaskerBridges\Phred\TableAdapter; class ListCommand implements CommandInterface { @@ -47,10 +48,18 @@ class ListCommand implements CommandInterface $commands = $this->runner->getCommands(); ksort($commands); + $table = new TableAdapter($output); + $table->setHeaders(['Command', 'Description']); + foreach ($commands as $name => $command) { - $output->writeln(sprintf(' %s %s', str_pad($name, 20), $command->getDescription())); + $table->addRow([ + "{$name}", + $command->getDescription() + ]); } + $table->render(); + return 0; } }