diff --git a/Command/Command.php b/Command/Command.php index e35ae51eb..71bf5d7c3 100644 --- a/Command/Command.php +++ b/Command/Command.php @@ -101,7 +101,18 @@ public function __construct(string $name = null) { $this->definition = new InputDefinition(); - if (null !== $name || null !== $name = static::getDefaultName()) { + if (null === $name && null !== $name = static::getDefaultName()) { + $aliases = explode('|', $name); + + if ('' === $name = array_shift($aliases)) { + $this->setHidden(true); + $name = array_shift($aliases); + } + + $this->setAliases($aliases); + } + + if (null !== $name) { $this->setName($name); } diff --git a/Tests/Command/CommandTest.php b/Tests/Command/CommandTest.php index 68c036621..839beac3f 100644 --- a/Tests/Command/CommandTest.php +++ b/Tests/Command/CommandTest.php @@ -414,6 +414,13 @@ public function testCommandAttribute() { $this->assertSame('|foo|f', Php8Command::getDefaultName()); $this->assertSame('desc', Php8Command::getDefaultDescription()); + + $command = new Php8Command(); + + $this->assertSame('foo', $command->getName()); + $this->assertSame('desc', $command->getDescription()); + $this->assertTrue($command->isHidden()); + $this->assertSame(['f'], $command->getAliases()); } }