Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Add option to run process command in dry-run mode #22

Merged
merged 2 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions fractor/src/Application/FractorRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,10 @@ public function run(Output $output, bool $dryRun = false): void
}


foreach ($this->fileCollector->getFiles() as $file) {
if ($dryRun) {
continue;
if (!$dryRun) {
foreach ($this->fileCollector->getFiles() as $file) {
$this->filePrinter->printFile($file);
}

$this->filePrinter->printFile($file);
}

$output->progressFinish();
Expand Down
19 changes: 19 additions & 0 deletions fractor/src/Configuration/Option.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,25 @@

final class Option
{
/**
* @var string
*/
public const PATHS = 'paths';
/**
* @var string
*/
public const SKIP = 'skip';
/**
* @var string
*/
public const DRY_RUN = 'dry-run';

/**
* @var string
*/
public const CONFIG = 'config';
/**
* @var string
*/
public const CONFIG_SHORT = 'c';
}
16 changes: 13 additions & 3 deletions fractor/src/Console/Command/ProcessCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace a9f\Fractor\Console\Command;

use a9f\Fractor\Application\FractorRunner;
use a9f\Fractor\Configuration\Option;
use a9f\Fractor\Console\Output\SymfonyConsoleOutput;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
Expand All @@ -21,16 +22,25 @@ public function __construct(private readonly FractorRunner $runner)
protected function configure(): void
{
$this->addOption(
'config',
'c',
Option::CONFIG,
Option::CONFIG_SHORT,
InputOption::VALUE_REQUIRED,
'The configuration file to use. Default: fractor.php in the current directory.'
);

$this->addOption(
Option::DRY_RUN,
null,
InputOption::VALUE_NONE,
'Only see the diff of changes, do not save them to files.'
);
}

protected function execute(InputInterface $input, OutputInterface $output): int
{
$this->runner->run(new SymfonyConsoleOutput($output));
$isDryRun = (bool) $input->getOption(Option::DRY_RUN);

$this->runner->run(new SymfonyConsoleOutput($output), $isDryRun);

return Command::SUCCESS;
}
Expand Down