Correction CliCommand : valeurs par défaut

master 3.8.1
Julien Rosset 9 months ago
parent c1c36475de
commit 438e256ca3

@ -68,14 +68,14 @@ class BaseCommand extends Command {
/** /**
* Initialize the command * Initialize the command
* *
* @param string|null $name The command name ; Null if the default one (cf. {@see static::getDefaultName()}) * @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[]|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 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 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); parent::__construct($name);
$this->setAliases($aliases ?? static::getDefaultAliases()); $this->setAliases(is_string($aliases) ? [$aliases] : $aliases ?? static::getDefaultAliases());
$this->setDescription($description ?? $this->getDescription()); $this->setDescription($description ?? $this->getDescription());
$this->setHidden($hidden ?? static::getDefaultHidden()); $this->setHidden($hidden ?? static::getDefaultHidden());
} }

@ -38,7 +38,7 @@ class CliCommand {
* @param string[] $aliases The command aliases * @param string[] $aliases The command aliases
* @param bool $hidden Is the command hidden from command list ? * @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->name = $name;
$this->description = $description; $this->description = $description;
$this->aliases = $aliases; $this->aliases = $aliases;

@ -4,6 +4,7 @@ namespace jrosset\Tests\Commands;
use DateTimeImmutable; use DateTimeImmutable;
use DateTimeInterface; use DateTimeInterface;
use jrosset\CliProgram\CliCommand;
use jrosset\CliProgram\Output\OutputWithLogger; use jrosset\CliProgram\Output\OutputWithLogger;
use jrosset\CliProgram\Validation\CommandWithValidation; use jrosset\CliProgram\Validation\CommandWithValidation;
use jrosset\CliProgram\Validation\Validators\DateValidator; 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\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
#[CliCommand(null, 'Say hello')]
#[SuccessRequirement] #[SuccessRequirement]
class Hello extends CommandWithValidation { class Hello extends CommandWithValidation {
/**
* @inheritdoc
*/
protected static $defaultDescription = 'Say hello';
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function __construct (?string $name = null) { public function __construct (?string $name = null) {
parent::__construct($name ?? 'hello', 'bonjour'); parent::__construct($name ?? 'hello', ['bonjour']);
} }
/** /**

Loading…
Cancel
Save