mirror of
https://github.com/opdavies/build-configs.git
synced 2025-01-23 02:27:33 +00:00
Don't generate files if the --dry-run
option is set
* Add the --dry-run option. * Add a warning if --dry-run is used saying no files have been generated.
This commit is contained in:
parent
85c370c438
commit
ea43e67da8
|
@ -16,6 +16,7 @@ final class GenerateConfigurationFiles
|
|||
private Filesystem $filesystem,
|
||||
private Environment $twig,
|
||||
private string $outputDir,
|
||||
private bool $isDryRun = false,
|
||||
) {
|
||||
}
|
||||
|
||||
|
@ -28,7 +29,10 @@ final class GenerateConfigurationFiles
|
|||
*/
|
||||
[$configurationData, $configurationDataDto, $filesToGenerate] = $filesToGenerateAndConfigurationData;
|
||||
|
||||
$filesToGenerate->each(function(TemplateFile $templateFile) use ($configurationData): void {
|
||||
if ($this->isDryRun) {
|
||||
return $next([$configurationDataDto, $filesToGenerate]);
|
||||
}
|
||||
|
||||
if ($templateFile->path !== null) {
|
||||
if (!$this->filesystem->exists($templateFile->path)) {
|
||||
$this->filesystem->mkdir("{$this->outputDir}/{$templateFile->path}");
|
||||
|
|
|
@ -51,6 +51,11 @@ class GenerateCommand extends Command
|
|||
description: 'The directory to create files in',
|
||||
default: '.',
|
||||
)
|
||||
->addOption(
|
||||
name: 'dry-run',
|
||||
mode: InputOption::VALUE_NONE,
|
||||
description: 'Whether to generate files or not',
|
||||
)
|
||||
;
|
||||
}
|
||||
|
||||
|
@ -60,18 +65,17 @@ class GenerateCommand extends Command
|
|||
|
||||
$configFile = $input->getOption(name: 'config-file');
|
||||
$outputDir = $input->getOption(name: 'output-dir');
|
||||
$isDryRun = $input->getOption(name: 'dry-run');
|
||||
|
||||
$pipelines = [
|
||||
new CreateFinalConfigurationData(),
|
||||
|
||||
new ValidateConfigurationData(),
|
||||
|
||||
new CreateListOfFilesToGenerate(),
|
||||
|
||||
new GenerateConfigurationFiles(
|
||||
$this->filesystem,
|
||||
$this->twig,
|
||||
$outputDir,
|
||||
$isDryRun,
|
||||
),
|
||||
];
|
||||
|
||||
|
@ -86,6 +90,10 @@ class GenerateCommand extends Command
|
|||
|
||||
$io->info("Building configuration for {$configurationData->name}.");
|
||||
|
||||
if ($isDryRun === true) {
|
||||
$io->warning('This is a dry run, no files have been generated.');
|
||||
}
|
||||
|
||||
$io->write('Generated files:');
|
||||
$io->listing(static::getListOfFiles(filesToGenerate: $generatedFiles)->toArray());
|
||||
|
||||
|
|
Loading…
Reference in a new issue