Correction CliCommand : valeurs par défaut

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

@ -69,13 +69,13 @@ 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[]|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());
}

@ -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;

@ -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']);
}
/**

Loading…
Cancel
Save