Add must-match-git-diff option

This commit is contained in:
Emanuele Minotto 2019-11-23 13:31:55 +01:00
parent 45a6df769f
commit 3b5432a5b1
3 changed files with 23 additions and 0 deletions

View File

@ -44,6 +44,11 @@ final class Configuration
*/
private $areAnyPhpRectorsLoaded = false;
/**
* @var bool
*/
private $mustMatchGitDiff = false;
/**
* Needs to run in the start of the life cycle, since the rest of workflow uses it.
*/
@ -51,6 +56,7 @@ final class Configuration
{
$this->isDryRun = (bool) $input->getOption(Option::OPTION_DRY_RUN);
$this->hideAutoloadErrors = (bool) $input->getOption(Option::HIDE_AUTOLOAD_ERRORS);
$this->mustMatchGitDiff = (bool) $input->getOption(Option::MUST_MATCH_GIT_DIFF);
$this->showProgressBar = $this->canShowProgressBar($input);
$this->setRule($input->getOption(Option::OPTION_RULE));
@ -115,6 +121,11 @@ final class Configuration
$this->areAnyPhpRectorsLoaded = $areAnyPhpRectorsLoaded;
}
public function mustMatchGitDiff(): bool
{
return $this->mustMatchGitDiff;
}
private function canShowProgressBar(InputInterface $input): bool
{
return $input->getOption(Option::OPTION_OUTPUT_FORMAT) !== JsonOutputFormatter::NAME;

View File

@ -65,4 +65,9 @@ final class Option
* @var string
*/
public const EXCLUDE_RECTORS_PARAMETER = 'exclude_rectors';
/**
* @var string
*/
public const MUST_MATCH_GIT_DIFF = 'must-match-git-diff';
}

View File

@ -148,6 +148,13 @@ final class ProcessCommand extends AbstractCommand
'Hide autoload errors for the moment.'
);
$this->addOption(
Option::MUST_MATCH_GIT_DIFF,
null,
InputOption::VALUE_NONE,
'Execute only on file matching the git diff.'
);
$this->addOption(Option::OPTION_RULE, 'r', InputOption::VALUE_REQUIRED, 'Run only this single rule.');
$availableOutputFormatters = $this->outputFormatterCollector->getNames();