diff --git a/src/Console/Command/BuildConfigurationCommand.php b/src/Console/Command/BuildConfigurationCommand.php index f431bbc..55f9f56 100644 --- a/src/Console/Command/BuildConfigurationCommand.php +++ b/src/Console/Command/BuildConfigurationCommand.php @@ -7,6 +7,7 @@ namespace OliverDaviesLtd\BuildConfiguration\Console\Command; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; use Symfony\Component\Filesystem\Filesystem; @@ -28,8 +29,16 @@ final class BuildConfigurationCommand extends Command parent::__construct(); } + protected function configure(): void + { + $this + ->addOption('output-dir', 'o', InputOption::VALUE_REQUIRED, 'The directory to create files in', '.'); + } + public function execute(InputInterface $input, OutputInterface $output): int { + $outputDir = $input->getOption('output-dir'); + $io = new SymfonyStyle($input, $output); $configurationData = Yaml::parseFile(getcwd().'/build.yaml'); @@ -38,17 +47,17 @@ final class BuildConfigurationCommand extends Command $io->info("Building configuration for {$configurationData['name']}."); - $this->filesystem->dumpFile('.env.example', $this->twig->render('env.example.twig', $configurationData)); - $this->filesystem->dumpFile('Dockerfile', $this->twig->render('Dockerfile.twig', $configurationData)); + $this->filesystem->dumpFile("{$outputDir}/.env.example", $this->twig->render('env.example.twig', $configurationData)); + $this->filesystem->dumpFile("{$outputDir}/Dockerfile", $this->twig->render('Dockerfile.twig', $configurationData)); if ($configurationData['dockerCompose'] === true) { - $this->filesystem->dumpFile('docker-compose.yaml', $this->twig->render('docker-compose.yaml.twig', $configurationData)); + $this->filesystem->dumpFile("{$outputDir}/docker-compose.yaml", $this->twig->render('docker-compose.yaml.twig', $configurationData)); } if ($configurationData['language'] === self::LANGUAGE_PHP) { - $this->filesystem->dumpFile('phpcs.xml.dist', $this->twig->render('phpcs.xml.twig', $configurationData)); - $this->filesystem->dumpFile('phpstan.neon.dist', $this->twig->render('phpstan.neon.twig', $configurationData)); - $this->filesystem->dumpFile('phpunit.xml.dist', $this->twig->render('phpunit.xml.twig', $configurationData)); + $this->filesystem->dumpFile("{$outputDir}/phpcs.xml.dist", $this->twig->render('phpcs.xml.twig', $configurationData)); + $this->filesystem->dumpFile("{$outputDir}/phpstan.neon.dist", $this->twig->render('phpstan.neon.twig', $configurationData)); + $this->filesystem->dumpFile("{$outputDir}/phpunit.xml.dist", $this->twig->render('phpunit.xml.twig', $configurationData)); } return Command::SUCCESS;