Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions bin/dload
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
17 changes: 17 additions & 0 deletions src/Command/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
*
Expand Down
Loading