diff --git a/bin/dload b/bin/dload old mode 100644 new mode 100755 index 9eca91d..053b8e8 --- a/bin/dload +++ b/bin/dload @@ -46,14 +46,14 @@ use Symfony\Component\Console\CommandLoader\FactoryCommandLoader; $application = new Application(); $application->setCommandLoader( new FactoryCommandLoader([ - Command\Get::getDefaultName() => static fn() => new Command\Get(), - Command\ListSoftware::getDefaultName() => static fn() => new Command\ListSoftware(), - Command\Show::getDefaultName() => static fn() => new Command\Show(), - Command\Init::getDefaultName() => static fn() => new Command\Init(), - Command\Build::getDefaultName() => static fn() => new Command\Build(), + Command\Get::getCommandName() => static fn() => new Command\Get(), + Command\ListSoftware::getCommandName() => static fn() => new Command\ListSoftware(), + Command\Show::getCommandName() => static fn() => new Command\Show(), + Command\Init::getCommandName() => static fn() => new Command\Init(), + Command\Build::getCommandName() => static fn() => new Command\Build(), ]), ); - $application->setDefaultCommand(Command\Get::getDefaultName(), false); + $application->setDefaultCommand(Command\Get::getCommandName(), false); $application->setVersion(Info::version()); $application->setName(Info::NAME); $application->run(); diff --git a/src/Command/Base.php b/src/Command/Base.php index 564c4cc..86411b4 100644 --- a/src/Command/Base.php +++ b/src/Command/Base.php @@ -7,6 +7,7 @@ use Internal\DLoad\Bootstrap; use Internal\DLoad\Service\Container; use Internal\DLoad\Service\Logger; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; @@ -43,6 +44,22 @@ abstract class Base extends Command /** @var Container IoC container with services */ protected Container $container; + public static function getCommandName(): ?string + { + if (!\class_exists(AsCommand::class)) { + // Fall back on lower Symfony versions + return self::getDefaultName(); + } + + if ($attributes = (new \ReflectionClass(static::class))->getAttributes(AsCommand::class)) { + /** @var AsCommand $attribute */ + $attribute = $attributes[0]->newInstance(); + return $attribute->name; + } + + return null; + } + /** * Configures command options. *