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 all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use a9f\Fractor\Application\ValueObject\File;

interface FilePrinter
interface FileWriter
{
public function printFile(File $file): void;
public function write(File $file): void;
}
6 changes: 3 additions & 3 deletions fractor/src/Application/FractorRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace a9f\Fractor\Application;

use a9f\Fractor\Application\Contract\FilePrinter;
use a9f\Fractor\Application\Contract\FileProcessor;
use a9f\Fractor\Application\Contract\FileWriter;
use a9f\Fractor\Application\ValueObject\File;
use a9f\Fractor\Configuration\ValueObject\Configuration;
use a9f\Fractor\Console\Contract\Output;
Expand All @@ -19,7 +19,7 @@
/**
* @param FileProcessor[] $processors
*/
public function __construct(private FilesFinder $fileFinder, private FilesCollector $fileCollector, private iterable $processors, private Configuration $configuration, private FilePrinter $filePrinter)
public function __construct(private FilesFinder $fileFinder, private FilesCollector $fileCollector, private iterable $processors, private Configuration $configuration, private FileWriter $fileWriter)
{
}

Expand Down Expand Up @@ -51,7 +51,7 @@ public function run(Output $output, bool $dryRun = false): void
continue;
}

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

$output->progressFinish();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

namespace a9f\Fractor\Application;

use a9f\Fractor\Application\Contract\FilePrinter;
use a9f\Fractor\Application\Contract\FileWriter;
use a9f\Fractor\Application\ValueObject\File;
use Nette\Utils\FileSystem;

final class LocalFileSystemPrinter implements FilePrinter
final class LocalFileSystemWriter implements FileWriter
{
public function printFile(File $file): void
public function write(File $file): void
{
FileSystem::write($file->getFilePath(), $file->getContent());
}
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