From 438e256ca31b40b504e521c29f00fced800736c0 Mon Sep 17 00:00:00 2001 From: Julien Rosset Date: Fri, 25 Oct 2024 12:40:44 +0200 Subject: [PATCH] =?UTF-8?q?Correction=20CliCommand=20:=20valeurs=20par=20d?= =?UTF-8?q?=C3=A9faut?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/CliProgram/BaseCommand.php | 12 ++++++------ src/CliProgram/CliCommand.php | 2 +- tests/Commands/Hello.php | 9 +++------ 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/src/CliProgram/BaseCommand.php b/src/CliProgram/BaseCommand.php index 6154979..4743488 100644 --- a/src/CliProgram/BaseCommand.php +++ b/src/CliProgram/BaseCommand.php @@ -68,14 +68,14 @@ class BaseCommand extends Command { /** * Initialize the command * - * @param string|null $name The command name ; Null if the default one (cf. {@see static::getDefaultName()}) - * @param string[]|null $aliases The command aliases ; Null if the default one (cf. {@see static::getDefaultAliases()}) - * @param string|null $description The command description ; Null if the default one (cf. {@see static::getDefaultDescription()}) - * @param bool|null $hidden Is the command hidden from command list ? Null if the default one (cf. {@see static::getDefaultHidden()}) + * @param string|null $name The command name ; Null if the default one (cf. {@see static::getDefaultName()}) + * @param string[]|string|null $aliases The command aliases ; Null if the default one (cf. {@see static::getDefaultAliases()}) + * @param string|null $description The command description ; Null if the default one (cf. {@see static::getDefaultDescription()}) + * @param bool|null $hidden Is the command hidden from command list ? Null if the default one (cf. {@see static::getDefaultHidden()}) */ - public function __construct (?string $name = null, ?array $aliases = null, ?string $description = null, ?bool $hidden = null) { + public function __construct (?string $name = null, array|string|null $aliases = null, ?string $description = null, ?bool $hidden = null) { parent::__construct($name); - $this->setAliases($aliases ?? static::getDefaultAliases()); + $this->setAliases(is_string($aliases) ? [$aliases] : $aliases ?? static::getDefaultAliases()); $this->setDescription($description ?? $this->getDescription()); $this->setHidden($hidden ?? static::getDefaultHidden()); } diff --git a/src/CliProgram/CliCommand.php b/src/CliProgram/CliCommand.php index 60d28eb..aa1d2e5 100644 --- a/src/CliProgram/CliCommand.php +++ b/src/CliProgram/CliCommand.php @@ -38,7 +38,7 @@ class CliCommand { * @param string[] $aliases The command aliases * @param bool $hidden Is the command hidden from command list ? */ - public function __construct (?string $name, ?string $description, array $aliases, bool $hidden) { + public function __construct (?string $name = null, ?string $description = null, array $aliases = [], bool $hidden = false) { $this->name = $name; $this->description = $description; $this->aliases = $aliases; diff --git a/tests/Commands/Hello.php b/tests/Commands/Hello.php index a78a654..03b5ed7 100644 --- a/tests/Commands/Hello.php +++ b/tests/Commands/Hello.php @@ -4,6 +4,7 @@ namespace jrosset\Tests\Commands; use DateTimeImmutable; use DateTimeInterface; +use jrosset\CliProgram\CliCommand; use jrosset\CliProgram\Output\OutputWithLogger; use jrosset\CliProgram\Validation\CommandWithValidation; use jrosset\CliProgram\Validation\Validators\DateValidator; @@ -17,18 +18,14 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; +#[CliCommand(null, 'Say hello')] #[SuccessRequirement] class Hello extends CommandWithValidation { - /** - * @inheritdoc - */ - protected static $defaultDescription = 'Say hello'; - /** * @inheritDoc */ public function __construct (?string $name = null) { - parent::__construct($name ?? 'hello', 'bonjour'); + parent::__construct($name ?? 'hello', ['bonjour']); } /**