Skip to content

Commit de36e23

Browse files
committed
auto-disable progress indicator when not running in a terminal
1 parent 8d9e1d7 commit de36e23

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

run.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php declare(strict_types=1);
22

3+
use Nette\CommandLine\Console;
34
use Nette\CommandLine\Parser;
45

56
const VERSION = '3.5.0';
@@ -30,6 +31,7 @@
3031
--config-file <path> Additional config file (.php for PHP CS Fixer, .xml for PHP_CodeSniffer).
3132
May be given twice (once per tool).
3233
--fix Shortcut for 'fix' mode.
34+
--no-progress Disable progress indicator.
3335
-h | --help Show this help.
3436
-V | --version Show version information.
3537

@@ -96,7 +98,8 @@
9698
if ($configFileXml !== null) {
9799
echo "Additional sniffer config: $configFileXml\n";
98100
}
99-
$checker = new Checker($vendorDir, $root, $dryRun, $preset, $configFileXml);
101+
$showProgress = !($options['--no-progress'] ?? false) && Console::detectTerminal();
102+
$checker = new Checker($vendorDir, $root, $dryRun, $preset, $configFileXml, $showProgress);
100103
echo 'Mode: ' . ($dryRun ? 'Check (dry-run)' : 'Fix') . "\n";
101104

102105
// Determine and set paths

src/Checker.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public function __construct(
2222
private bool $dryRun = true,
2323
private ?string $preset = null,
2424
private ?string $snifferConfig = null,
25+
private bool $showProgress = true,
2526
) {
2627
$this->fileListPath = dirname(__DIR__) . '/filelist.tmp';
2728
}
@@ -150,9 +151,8 @@ public function runSniffer(): bool
150151
. (php_ini_loaded_file() ? ' -c ' . escapeshellarg(php_ini_loaded_file()) : '')
151152
. ' ' . escapeshellarg($snifferBin)
152153
. ' -s' // show sniff codes, works only in dry mode :-(
153-
. ' -p' // progress
154+
. ($this->showProgress ? ' -p --colors' : '')
154155
. $phpVersionOption
155-
. ' --colors'
156156
. ' --extensions=php,phpt'
157157
. ' --runtime-set ignore_warnings_on_exit true'
158158
. ' --no-cache'

0 commit comments

Comments
 (0)