Skip to content

Commit 492659f

Browse files
committed
Adds a flavour option
1 parent 1bbafa7 commit 492659f

3 files changed

Lines changed: 62 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
1111

1212
### Added
1313
- Expanded the `validation` to also validate __negated__ export-ignore directives. Closes [#70](https://github.com/raphaelstolt/lean-package-validator/issues/70).
14+
- New `--flavour` option for the `create` command which influences the `.gitattributes` generation. Closes [#71](https://github.com/raphaelstolt/lean-package-validator/issues/71).
1415

1516
## [v5.9.1] - 2026-05-17
1617

src/Commands/CreateCommand.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,25 @@ protected function configure(): void
5555
$this->addAgenticOutputOption(function (...$args) {
5656
$this->getDefinition()->addOption(new InputOption(...$args));
5757
});
58+
$flavourDescription = 'Generate the .gitattributes file with the given flavour';
59+
60+
$this->addOption('flavour', 'f', InputOption::VALUE_OPTIONAL, $flavourDescription, 'classic');
5861
}
5962

6063
protected function execute(InputInterface $input, OutputInterface $output): int
6164
{
6265
$directory = (string) $input->getArgument('directory') ?: \getcwd();
6366
$this->analyser->setDirectory($directory);
67+
6468
$isAgenticRun = $this->isAgenticRun($input);
6569

70+
$generationFlavour = $input->getOption('flavour') ?: 'classic';
71+
72+
if ($generationFlavour && !\in_array($generationFlavour, ['classic', 'negated'], true)) {
73+
$output->writeln('<error>Invalid flavour specified. Use <info>classic</info> or <info>negated</info>.</error>');
74+
return self::FAILURE;
75+
}
76+
6677
// Apply options that influence generation
6778
if (!$this->applyGenerationOptions($input, $output, $this->analyser)) {
6879
return self::FAILURE;

tests/Commands/CreateCommandTest.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,56 @@ protected function tearDown(): void
2626
$this->removeDirectory($this->temporaryDirectory);
2727
}
2828

29+
#[Test]
30+
public function failsForUnknownFlavour(): void
31+
{
32+
$analyser = (new Analyser(new Finder(new PhpPreset())))->setDirectory($this->temporaryDirectory);
33+
$repository = new GitattributesFileRepository($analyser);
34+
$command = new CreateCommand($analyser, $repository);
35+
36+
TestCommand::for($command)
37+
->addArgument($this->temporaryDirectory)
38+
->addOption('flavour', 'unknown')
39+
->execute()
40+
->assertFaulty()
41+
->assertOutputContains('Invalid flavour specified. Use classic or negated');
42+
}
43+
44+
#[Test]
45+
public function createsAGitattributesFileWithNegatedExportIgnoreDirectives(): void
46+
{
47+
$analyser = (new Analyser(new Finder(new PhpPreset())))->setDirectory($this->temporaryDirectory);
48+
$repository = new GitattributesFileRepository($analyser);
49+
$command = new CreateCommand($analyser, $repository);
50+
51+
$artifactFilenames = ['LICENSE.md', '.gitignore', 'composer.json'];
52+
53+
$this->createTemporaryFiles(
54+
$artifactFilenames,
55+
['tests', 'src', 'bin']
56+
);
57+
58+
TestCommand::for($command)
59+
->addArgument($this->temporaryDirectory)
60+
->addOption('flavour', 'negated')
61+
->addOption('keep-license')
62+
->execute()
63+
->assertSuccessful();
64+
65+
$expectedGitattributesContent = <<<CONTENT
66+
* export-ignore
67+
68+
composer.json -export-ignore
69+
LICENSE.md -export-ignore
70+
71+
src/ -export-ignore
72+
bin/ -export-ignore
73+
CONTENT;
74+
75+
$this->assertFileExists($this->temporaryDirectory . DIRECTORY_SEPARATOR . '.gitattributes');
76+
$this->assertStringEqualsFile($this->temporaryDirectory . DIRECTORY_SEPARATOR . '.gitattributes', $expectedGitattributesContent);
77+
}
78+
2979
#[Test]
3080
public function createsNewGitattributesFileWithHeaderAndExpectedContent(): void
3181
{

0 commit comments

Comments
 (0)