Skip to content

Commit 07df53d

Browse files
committed
[FEATURE] Suppress diff output in quiet mode
1 parent ce5e05e commit 07df53d

File tree

6 files changed

+45
-15
lines changed

6 files changed

+45
-15
lines changed

e2e/run-test.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ cd $TEST_DIR
1818
cp -r fixtures/ output/
1919

2020
cd $TESTS_BASE_DIR
21-
./vendor/bin/fractor process -c $TESTS_BASE_DIR/$TEST_DIR/fractor.php
21+
./vendor/bin/fractor process --quiet -c $TESTS_BASE_DIR/$TEST_DIR/fractor.php
2222

2323
# TODO remove -b once we keep the output format when re-writing the file
2424
diff -rub $TEST_DIR/expected-output/ $TEST_DIR/output/

fractor/src/Application/FractorRunner.php

+19-12
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,23 @@ public function run(Output $output, Configuration $configuration): void
3939
{
4040
$filePaths = $this->fileFinder->findFiles($configuration->getPaths(), $configuration->getFileExtensions());
4141

42-
$output->progressStart(count($filePaths));
42+
if (! $configuration->isQuiet()) {
43+
$output->progressStart(count($filePaths));
44+
}
4345

4446
foreach ($filePaths as $filePath) {
4547
$file = new File($filePath, FileSystem::read($filePath));
4648
$this->fileCollector->addFile($file);
4749

4850
foreach ($this->processors as $processor) {
49-
if (! $processor->canHandle($file)) {
51+
if (! $configuration->isQuiet()) {
5052
$output->progressAdvance();
53+
}
54+
if (! $processor->canHandle($file)) {
5155
continue;
5256
}
5357

5458
$processor->handle($file);
55-
$output->progressAdvance();
5659
}
5760

5861
if (! $file->hasChanged()) {
@@ -62,21 +65,25 @@ public function run(Output $output, Configuration $configuration): void
6265
$file->setFileDiff($this->fileDiffFactory->createFileDiff($file));
6366
}
6467

65-
$output->progressFinish();
68+
if (! $configuration->isQuiet()) {
69+
$output->progressFinish();
70+
}
6671

6772
foreach ($this->fileCollector->getFiles() as $file) {
6873
if ($file->getFileDiff() === null) {
6974
continue;
7075
}
7176

72-
$output->write($file->getFileDiff()->getDiffConsoleFormatted());
73-
if ($file->getAppliedRules() !== []) {
74-
$fractorsChangelogsLines = $this->fractorsChangelogLinesResolver->createFractorChangelogLines(
75-
$file->getAppliedRules()
76-
);
77-
$output->write('<options=underscore>Applied rules:</>');
78-
$output->listing($fractorsChangelogsLines);
79-
$output->newLine();
77+
if (! $configuration->isQuiet()) {
78+
$output->write($file->getFileDiff()->getDiffConsoleFormatted());
79+
if ($file->getAppliedRules() !== []) {
80+
$fractorsChangelogsLines = $this->fractorsChangelogLinesResolver->createFractorChangelogLines(
81+
$file->getAppliedRules()
82+
);
83+
$output->write('<options=underscore>Applied rules:</>');
84+
$output->listing($fractorsChangelogsLines);
85+
$output->newLine();
86+
}
8087
}
8188

8289
if ($configuration->isDryRun()) {

fractor/src/Configuration/ConfigurationFactory.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ public function createFromInput(InputInterface $input): Configuration
2323
$this->allowedFileExtensionsResolver->resolve(),
2424
(array) $this->parameterBag->get(Option::PATHS),
2525
(array) $this->parameterBag->get(Option::SKIP),
26-
(bool) $input->getOption(Option::DRY_RUN)
26+
(bool) $input->getOption(Option::DRY_RUN),
27+
(bool) $input->getOption(Option::QUIET)
2728
);
2829
}
2930

fractor/src/Configuration/Option.php

+10
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@ final class Option
2121
*/
2222
public const DRY_RUN = 'dry-run';
2323

24+
/**
25+
* @var string
26+
*/
27+
public const QUIET = 'quiet';
28+
29+
/**
30+
* @var string
31+
*/
32+
public const QUIET_SHORT = 'q';
33+
2434
/**
2535
* @var string
2636
*/

fractor/src/Configuration/ValueObject/Configuration.php

+7-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ public function __construct(
1717
private array $fileExtensions,
1818
private array $paths,
1919
private array $skip,
20-
private bool $dryRun
20+
private bool $dryRun,
21+
private bool $quiet
2122
) {
2223
Assert::allStringNotEmpty($this->paths, 'No directories given');
2324
}
@@ -50,4 +51,9 @@ public function isDryRun(): bool
5051
{
5152
return $this->dryRun;
5253
}
54+
55+
public function isQuiet(): bool
56+
{
57+
return $this->quiet;
58+
}
5359
}

fractor/src/Console/Command/ProcessCommand.php

+6
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ protected function configure(): void
3939
InputOption::VALUE_NONE,
4040
'Only see the diff of changes, do not save them to files.'
4141
);
42+
$this->addOption(
43+
Option::QUIET,
44+
Option::QUIET_SHORT,
45+
InputOption::VALUE_NONE,
46+
'Do not output diff of changes.'
47+
);
4248
}
4349

4450
protected function execute(InputInterface $input, OutputInterface $output): int

0 commit comments

Comments
 (0)