Use annotations and autoconfiguration

Use the `AsCommand` annotation to automatically register commands as
services and automatically add them to `./bin/console` instead of adding
them manually.
This commit is contained in:
Oliver Davies 2024-02-26 20:40:58 +00:00
parent bfc9a89842
commit 4ebfd9333a
17 changed files with 78 additions and 81 deletions

View file

@ -8,15 +8,17 @@ use App\Enum\PackageManager;
use App\Enum\ProjectLanguage;
use App\Process\Process;
use RuntimeException;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Filesystem\Filesystem;
#[AsCommand(
description: 'Install the project\'s dependencies',
name: 'install',
)]
final class InstallCommand extends AbstractCommand
{
public static string $description = 'Install the project\'s dependencies';
public function execute(InputInterface $input, OutputInterface $output): int
{
$args = $input->getOption('args');
@ -27,8 +29,6 @@ final class InstallCommand extends AbstractCommand
workingDir: $workingDir,
))->getLanguage();
$filesystem = new Filesystem();
// TODO: Composer in Docker Compose?
$process = Process::create(
args: explode(separator: ' ', string: strval($args)),