Skip to content

Commit

Permalink
[PMakowski] squizlabs#2.5.1.x-dev: Adding option to define editor pat…
Browse files Browse the repository at this point in the history
…h and open files in that during interactive session
  • Loading branch information
Piotr Makowski authored and Astinus-Eberhard committed Jun 8, 2018
1 parent ba816f2 commit 1e78c77
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
12 changes: 11 additions & 1 deletion src/Config.php
Expand Up @@ -115,6 +115,7 @@ class Config
'tabWidth' => null,
'encoding' => null,
'extensions' => null,
'editorPath' => null,
'sniffs' => null,
'exclude' => null,
'ignored' => null,
Expand Down Expand Up @@ -472,6 +473,7 @@ public function restoreDefaults()
$this->reportFile = null;
$this->generator = null;
$this->filter = null;
$this->editorPath = null;
$this->bootstrap = [];
$this->basepath = null;
$this->reports = ['full' => null];
Expand All @@ -490,6 +492,11 @@ public function restoreDefaults()
$this->standards = explode(',', $standard);
}

$editorPath = self::getConfigData('editorPath');
if ($editorPath !== null) {
$this->editorPath = $editorPath;
}

$reportFormat = self::getConfigData('report_format');
if ($reportFormat !== null) {
$this->reports = [$reportFormat => null];
Expand Down Expand Up @@ -821,6 +828,9 @@ public function processLongArgument($arg, $pos)

$this->sniffs = $sniffs;
$this->overriddenDefaults['sniffs'] = true;
} else if (substr($arg, 0, 12) === 'editor-path=') {
$this->editorPath = substr($arg, 12);
$this->overriddenDefaults['editorPath'] = true;
} else if (substr($arg, 0, 8) === 'exclude=') {
if (isset($this->overriddenDefaults['exclude']) === true) {
break;
Expand Down Expand Up @@ -1338,7 +1348,7 @@ public function printPHPCSUsage()
echo ' [--report-width=<reportWidth>] [--basepath=<basepath>] [--bootstrap=<bootstrap>]'.PHP_EOL;
echo ' [--severity=<severity>] [--error-severity=<severity>] [--warning-severity=<severity>]'.PHP_EOL;
echo ' [--runtime-set key value] [--config-set key value] [--config-delete key] [--config-show]'.PHP_EOL;
echo ' [--standard=<standard>] [--sniffs=<sniffs>] [--exclude=<sniffs>]'.PHP_EOL;
echo ' [--standard=<standard>] [--sniffs=<sniffs>] [--exclude=<sniffs>] [--editor-path=<path>]'.PHP_EOL;
echo ' [--encoding=<encoding>] [--parallel=<processes>] [--generator=<generator>]'.PHP_EOL;
echo ' [--extensions=<extensions>] [--ignore=<patterns>] [--ignore-annotations]'.PHP_EOL;
echo ' [--stdin-path=<stdinPath>] [--file-list=<fileList>] <file> - ...'.PHP_EOL;
Expand Down
6 changes: 5 additions & 1 deletion src/Runner.php
Expand Up @@ -627,7 +627,7 @@ public function processFile($file)

$this->reporter->printReport('full');

echo '<ENTER> to recheck, [s] to skip or [q] to quit : ';
echo '<ENTER> to recheck, [s] to skip'.($this->config->editorPath ? ', [o] to open in editor' : null).' or [q] to quit : ';
$input = fgets(STDIN);
$input = trim($input);

Expand All @@ -636,6 +636,10 @@ public function processFile($file)
break(2);
case 'q':
throw new DeepExitException('', 0);
case 'o':
if ($this->config->editorPath) {
exec($this->config->editorPath.' '.$file->path);
}
default:
// Repopulate the sniffs because some of them save their state
// and only clear it when the file changes, but we are rechecking
Expand Down

0 comments on commit 1e78c77

Please sign in to comment.