Skip to content

Commit ef4bb6e

Browse files
committed
[FEATURE] Add option to run process command in dry-run mode
1 parent 21d5277 commit ef4bb6e

File tree

3 files changed

+29
-6
lines changed

3 files changed

+29
-6
lines changed

fractor/src/Application/FractorRunner.php

+3-5
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,10 @@ public function run(Output $output, bool $dryRun = false): void
4646
}
4747

4848

49-
foreach ($this->fileCollector->getFiles() as $file) {
50-
if ($dryRun) {
51-
continue;
49+
if (!$dryRun) {
50+
foreach ($this->fileCollector->getFiles() as $file) {
51+
$this->filePrinter->printFile($file);
5252
}
53-
54-
$this->filePrinter->printFile($file);
5553
}
5654

5755
$output->progressFinish();

fractor/src/Configuration/Option.php

+15
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,21 @@
66

77
final class Option
88
{
9+
/**
10+
* @var string
11+
*/
912
public const PATHS = 'paths';
13+
/**
14+
* @var string
15+
*/
1016
public const SKIP = 'skip';
17+
/**
18+
* @var string
19+
*/
20+
public const DRY_RUN = 'dry-run';
21+
22+
/**
23+
* @var string
24+
*/
25+
public const DRY_RUN_SHORT = 'n';
1126
}

fractor/src/Console/Command/ProcessCommand.php

+11-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace a9f\Fractor\Console\Command;
44

55
use a9f\Fractor\Application\FractorRunner;
6+
use a9f\Fractor\Configuration\Option;
67
use a9f\Fractor\Console\Output\SymfonyConsoleOutput;
78
use Symfony\Component\Console\Attribute\AsCommand;
89
use Symfony\Component\Console\Command\Command;
@@ -26,11 +27,20 @@ protected function configure(): void
2627
InputOption::VALUE_REQUIRED,
2728
'The configuration file to use. Default: fractor.php in the current directory.'
2829
);
30+
31+
$this->addOption(
32+
Option::DRY_RUN,
33+
Option::DRY_RUN_SHORT,
34+
InputOption::VALUE_NONE,
35+
'Only see the diff of changes, do not save them to files.'
36+
);
2937
}
3038

3139
protected function execute(InputInterface $input, OutputInterface $output): int
3240
{
33-
$this->runner->run(new SymfonyConsoleOutput($output));
41+
$isDryRun = (bool) $input->getOption(Option::DRY_RUN);
42+
43+
$this->runner->run(new SymfonyConsoleOutput($output), $isDryRun);
3444

3545
return Command::SUCCESS;
3646
}

0 commit comments

Comments
 (0)