|
4 | 4 |
|
5 | 5 | namespace Stolt\LeanPackage\Commands; |
6 | 6 |
|
| 7 | +use function PHPUnit\Framework\stringContains; |
7 | 8 | use SebastianBergmann\Diff\Differ; |
8 | 9 | use SebastianBergmann\Diff\Output\UnifiedDiffOutputBuilder; |
9 | 10 | use SplFileInfo; |
|
17 | 18 | use Stolt\LeanPackage\Exceptions\InvalidGlobPatternFile; |
18 | 19 | use Stolt\LeanPackage\Exceptions\NoLicenseFilePresent; |
19 | 20 | use Stolt\LeanPackage\Exceptions\NonExistentGlobPatternFile; |
| 21 | +use Stolt\LeanPackage\Helpers\InputReader; |
20 | 22 | use Symfony\Component\Console\Command\Command; |
21 | 23 | use Symfony\Component\Console\Input\InputArgument; |
22 | 24 | use Symfony\Component\Console\Input\InputInterface; |
@@ -47,13 +49,22 @@ final class ValidateCommand extends Command |
47 | 49 | protected Validator $archiveValidator; |
48 | 50 |
|
49 | 51 | /** |
50 | | - * @param Analyser $analyser |
| 52 | + * Input reader. |
| 53 | + * |
| 54 | + * @var InputReader |
| 55 | + */ |
| 56 | + protected InputReader $inputReader; |
| 57 | + |
| 58 | + /** |
| 59 | + * @param Analyser $analyser |
51 | 60 | * @param Validator $archiveValidator |
| 61 | + * @param InputReader $inputReader |
52 | 62 | */ |
53 | | - public function __construct(Analyser $analyser, Validator $archiveValidator) |
| 63 | + public function __construct(Analyser $analyser, Validator $archiveValidator, InputReader $inputReader) |
54 | 64 | { |
55 | 65 | $this->analyser = $analyser; |
56 | 66 | $this->archiveValidator = $archiveValidator; |
| 67 | + $this->inputReader = $inputReader; |
57 | 68 |
|
58 | 69 | parent::__construct(); |
59 | 70 | } |
@@ -105,7 +116,9 @@ protected function configure(): void |
105 | 116 | $sortDescription = 'Sort from directories to files'; |
106 | 117 |
|
107 | 118 | $alignExportIgnoresDescription = 'Align export-ignores on create or overwrite'; |
| 119 | + $stdinInputDescription = "Read .gitattributes content from standard input"; |
108 | 120 |
|
| 121 | + $this->addOption('stdin-input', null, InputOption::VALUE_NONE, $stdinInputDescription); |
109 | 122 | $this->addOption('create', 'c', InputOption::VALUE_NONE, $createDescription); |
110 | 123 | $this->addOption( |
111 | 124 | 'enforce-strict-order', |
@@ -220,6 +233,35 @@ protected function execute(InputInterface $input, OutputInterface $output): int |
220 | 233 | } |
221 | 234 | } |
222 | 235 |
|
| 236 | + $stdinInput = $input->getOption('stdin-input'); |
| 237 | + |
| 238 | + if ($stdinInput !== false) { |
| 239 | + $stdinInputContents = $this->inputReader->get(); |
| 240 | + |
| 241 | + if (!\strpos($stdinInputContents, 'export-ignore')) { |
| 242 | + $warning = "Warning: The provided input stream seems to be no .gitattributes content."; |
| 243 | + $outputContent = '<error>' . $warning . '</error>'; |
| 244 | + $output->writeln($outputContent); |
| 245 | + |
| 246 | + return Command::FAILURE; |
| 247 | + } |
| 248 | + |
| 249 | + $verboseOutput = '+ Validating .gitattributes content from STDIN.'; |
| 250 | + $output->writeln($verboseOutput, OutputInterface::VERBOSITY_VERBOSE); |
| 251 | + |
| 252 | + if ($this->analyser->hasCompleteExportIgnoresFromString($stdinInputContents)) { |
| 253 | + $info = 'The provided .gitattributes content is considered <info>valid</info>.'; |
| 254 | + $output->writeln($info); |
| 255 | + |
| 256 | + return Command::SUCCESS; |
| 257 | + } |
| 258 | + |
| 259 | + $outputContent = 'The provided .gitattributes file is considered <error>invalid</error>.'; |
| 260 | + $output->writeln($outputContent); |
| 261 | + |
| 262 | + return Command::FAILURE; |
| 263 | + } |
| 264 | + |
223 | 265 | $verboseOutput = '+ Scanning directory ' . $directory . '.'; |
224 | 266 | $output->writeln($verboseOutput, OutputInterface::VERBOSITY_VERBOSE); |
225 | 267 |
|
@@ -302,7 +344,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int |
302 | 344 | } |
303 | 345 | } |
304 | 346 |
|
305 | | - |
306 | 347 | $alignExportIgnores = $input->getOption('align-export-ignores'); |
307 | 348 |
|
308 | 349 | if ($alignExportIgnores) { |
|
0 commit comments