From 6671ec3eac123e7a5b4e2882311676ad61af9a59 Mon Sep 17 00:00:00 2001 From: Christopher Vagnetoft Date: Sat, 18 Jan 2025 21:58:51 +0100 Subject: [PATCH] Allow providing manual signature hint to commands --- src/Command.php | 10 +++++++++- tests/CommandTest.php | 4 ++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/Command.php b/src/Command.php index a3bfe11..2c5278f 100644 --- a/src/Command.php +++ b/src/Command.php @@ -19,10 +19,13 @@ class Command /** @var callable $handler The handler */ private $handler; - public function __construct(string $name, callable $handler) + private ?array $signature; + + public function __construct(string $name, callable $handler, ?array $signature = null) { $this->name = $name; $this->handler = $handler; + $this->signature = $signature; } public function getName(): string @@ -66,5 +69,10 @@ class Command return $args; } + public function getSignature(): array + { + return $this->signature ?? $this->parameters(); + } + } diff --git a/tests/CommandTest.php b/tests/CommandTest.php index 54d30f0..f5fe8fe 100644 --- a/tests/CommandTest.php +++ b/tests/CommandTest.php @@ -31,8 +31,8 @@ class CommandTest extends \PHPUnit\Framework\TestCase $command = new Command("test", function (string $a, ?int $b, bool $c = false) { }); $expect = [ 'a' => 'string', - 'b' => 'int', - 'c' => '?bool' + 'b' => '?int', + 'c' => 'bool=false' ]; $this->assertEquals($expect, $command->parameters()); }