Skip to content

Commit 9866270

Browse files
committed
Added --no-progress option (#99)
1 parent b4e044c commit 9866270

File tree

4 files changed

+69
-21
lines changed

4 files changed

+69
-21
lines changed

src/Manager.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,14 @@ protected function getDefaultOutput(Settings $settings)
108108
return new JsonOutput($writer);
109109
} else {
110110
if ($settings->colors === Settings::DISABLED) {
111-
return new TextOutput($writer);
111+
$output = new TextOutput($writer);
112+
} else {
113+
$output = new TextOutputColored($writer, $settings->colors);
112114
}
113-
return new TextOutputColored($writer, $settings->colors);
115+
116+
$output->showProgress = $settings->showProgress;
117+
118+
return $output;
114119
}
115120
}
116121

src/Output.php

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,15 @@ class TextOutput implements Output
119119
const TYPE_DEFAULT = 'default',
120120
TYPE_SKIP = 'skip',
121121
TYPE_ERROR = 'error',
122+
TYPE_FAIL = 'fail',
122123
TYPE_OK = 'ok';
123124

124125
/** @var int */
125126
public $filesPerLine = 60;
126127

128+
/** @var bool */
129+
public $showProgress = true;
130+
127131
/** @var int */
128132
protected $checkedFiles;
129133

@@ -143,26 +147,22 @@ public function __construct(IWriter $writer)
143147

144148
public function ok()
145149
{
146-
$this->writer->write('.');
147-
$this->progress();
150+
$this->writeMark(self::TYPE_OK);
148151
}
149152

150153
public function skip()
151154
{
152-
$this->write('S', self::TYPE_SKIP);
153-
$this->progress();
155+
$this->writeMark(self::TYPE_SKIP);
154156
}
155157

156158
public function error()
157159
{
158-
$this->write('X', self::TYPE_ERROR);
159-
$this->progress();
160+
$this->writeMark(self::TYPE_ERROR);
160161
}
161162

162163
public function fail()
163164
{
164-
$this->writer->write('-');
165-
$this->progress();
165+
$this->writeMark(self::TYPE_FAIL);
166166
}
167167

168168
/**
@@ -227,13 +227,15 @@ public function writeHeader($phpVersion, $parallelJobs, $hhvmVersion = null)
227227
*/
228228
public function writeResult(Result $result, ErrorFormatter $errorFormatter, $ignoreFails)
229229
{
230-
if ($this->checkedFiles % $this->filesPerLine !== 0) {
231-
$rest = $this->filesPerLine - ($this->checkedFiles % $this->filesPerLine);
232-
$this->write(str_repeat(' ', $rest));
233-
$this->writeProgress();
234-
}
230+
if ($this->showProgress) {
231+
if ($this->checkedFiles % $this->filesPerLine !== 0) {
232+
$rest = $this->filesPerLine - ($this->checkedFiles % $this->filesPerLine);
233+
$this->write(str_repeat(' ', $rest));
234+
$this->writePercent();
235+
}
235236

236-
$this->writeNewLine(2);
237+
$this->writeNewLine(2);
238+
}
237239

238240
$testTime = round($result->getTestTime(), 1);
239241
$message = "Checked {$result->getCheckedFilesCount()} files in $testTime ";
@@ -274,16 +276,31 @@ public function writeResult(Result $result, ErrorFormatter $errorFormatter, $ign
274276
}
275277
}
276278

277-
protected function progress()
279+
protected function writeMark($type)
278280
{
279281
++$this->checkedFiles;
280282

281-
if ($this->checkedFiles % $this->filesPerLine === 0) {
282-
$this->writeProgress();
283+
if ($this->showProgress) {
284+
if ($type === self::TYPE_OK) {
285+
$this->writer->write('.');
286+
287+
} elseif ($type === self::TYPE_SKIP) {
288+
$this->write('S', self::TYPE_SKIP);
289+
290+
} elseif ($type === self::TYPE_ERROR) {
291+
$this->write('X', self::TYPE_ERROR);
292+
293+
} elseif ($type === self::TYPE_FAIL) {
294+
$this->writer->write('-');
295+
}
296+
297+
if ($this->checkedFiles % $this->filesPerLine === 0) {
298+
$this->writePercent();
299+
}
283300
}
284301
}
285302

286-
protected function writeProgress()
303+
protected function writePercent()
287304
{
288305
$percent = floor($this->checkedFiles / $this->totalFileCount * 100);
289306
$current = $this->stringWidth($this->checkedFiles, strlen($this->totalFileCount));

src/Settings.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class Settings
7777
public $paths = array();
7878

7979
/**
80-
* Dont't check files or directories
80+
* Don't check files or directories
8181
* @var array
8282
*/
8383
public $excluded = array();
@@ -88,6 +88,12 @@ class Settings
8888
*/
8989
public $colors = self::AUTODETECT;
9090

91+
/**
92+
* Show progress in text output
93+
* @var bool
94+
*/
95+
public $showProgress = true;
96+
9197
/**
9298
* Output results as JSON string
9399
* @var bool
@@ -174,6 +180,10 @@ public static function parseArguments(array $arguments)
174180
$settings->colors = self::DISABLED;
175181
break;
176182

183+
case '--no-progress':
184+
$settings->showProgress = false;
185+
break;
186+
177187
case '--json':
178188
$settings->json = true;
179189
break;

tests/Settings.parseArguments.phpt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class SettingsParseArgumentsTest extends Tester\TestCase
2626
$expectedSettings->paths = array('.');
2727
$expectedSettings->excluded = array();
2828
$expectedSettings->colors = Settings::AUTODETECT;
29+
$expectedSettings->showProgress = true;
2930
$expectedSettings->json = false;
3031

3132
Assert::equal($expectedSettings->phpExecutable, $settings->phpExecutable);
@@ -36,6 +37,7 @@ class SettingsParseArgumentsTest extends Tester\TestCase
3637
Assert::equal($expectedSettings->paths, $settings->paths);
3738
Assert::equal($expectedSettings->excluded, $settings->excluded);
3839
Assert::equal($expectedSettings->colors, $settings->colors);
40+
Assert::equal($expectedSettings->showProgress, $settings->showProgress);
3941
Assert::equal($expectedSettings->json, $settings->json);
4042
}
4143

@@ -54,6 +56,7 @@ class SettingsParseArgumentsTest extends Tester\TestCase
5456
$expectedSettings->paths = array('.');
5557
$expectedSettings->excluded = array('vendor');
5658
$expectedSettings->colors = Settings::DISABLED;
59+
$expectedSettings->showProgress = true;
5760
$expectedSettings->json = false;
5861

5962
Assert::equal($expectedSettings->phpExecutable, $settings->phpExecutable);
@@ -64,6 +67,7 @@ class SettingsParseArgumentsTest extends Tester\TestCase
6467
Assert::equal($expectedSettings->paths, $settings->paths);
6568
Assert::equal($expectedSettings->excluded, $settings->excluded);
6669
Assert::equal($expectedSettings->colors, $settings->colors);
70+
Assert::equal($expectedSettings->showProgress, $settings->showProgress);
6771
Assert::equal($expectedSettings->json, $settings->json);
6872
}
6973

@@ -78,6 +82,18 @@ class SettingsParseArgumentsTest extends Tester\TestCase
7882

7983
Assert::equal($expectedSettings->colors, $settings->colors);
8084
}
85+
86+
public function testNoProgress()
87+
{
88+
$commandLine = "./parallel-lint --exclude vendor --no-progress .";
89+
$argv = explode(" ", $commandLine);
90+
$settings = Settings::parseArguments($argv);
91+
92+
$expectedSettings = new Settings();
93+
$expectedSettings->showProgress = false;
94+
95+
Assert::equal($expectedSettings->colors, $settings->colors);
96+
}
8197
}
8298

8399
$testCase = new SettingsParseArgumentsTest;

0 commit comments

Comments
 (0)