Skip to content
This repository has been archived by the owner on Jul 1, 2023. It is now read-only.

Commit

Permalink
Added --no-progress option (#99)
Browse files Browse the repository at this point in the history
  • Loading branch information
JakubOnderka committed May 27, 2017
1 parent 8333664 commit 6e0077a
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 21 deletions.
9 changes: 7 additions & 2 deletions src/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,14 @@ protected function getDefaultOutput(Settings $settings)
return new JsonOutput($writer);
} else {
if ($settings->colors === Settings::DISABLED) {
return new TextOutput($writer);
$output = new TextOutput($writer);
} else {
$output = new TextOutputColored($writer, $settings->colors);
}
return new TextOutputColored($writer, $settings->colors);

$output->showProgress = $settings->showProgress;

return $output;
}
}

Expand Down
53 changes: 35 additions & 18 deletions src/Output.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,15 @@ class TextOutput implements Output
const TYPE_DEFAULT = 'default',
TYPE_SKIP = 'skip',
TYPE_ERROR = 'error',
TYPE_FAIL = 'fail',
TYPE_OK = 'ok';

/** @var int */
public $filesPerLine = 60;

/** @var bool */
public $showProgress = true;

/** @var int */
protected $checkedFiles;

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

public function ok()
{
$this->writer->write('.');
$this->progress();
$this->writeMark(self::TYPE_OK);
}

public function skip()
{
$this->write('S', self::TYPE_SKIP);
$this->progress();
$this->writeMark(self::TYPE_SKIP);
}

public function error()
{
$this->write('X', self::TYPE_ERROR);
$this->progress();
$this->writeMark(self::TYPE_ERROR);
}

public function fail()
{
$this->writer->write('-');
$this->progress();
$this->writeMark(self::TYPE_FAIL);
}

/**
Expand Down Expand Up @@ -227,13 +227,15 @@ public function writeHeader($phpVersion, $parallelJobs, $hhvmVersion = null)
*/
public function writeResult(Result $result, ErrorFormatter $errorFormatter, $ignoreFails)
{
if ($this->checkedFiles % $this->filesPerLine !== 0) {
$rest = $this->filesPerLine - ($this->checkedFiles % $this->filesPerLine);
$this->write(str_repeat(' ', $rest));
$this->writeProgress();
}
if ($this->showProgress) {
if ($this->checkedFiles % $this->filesPerLine !== 0) {
$rest = $this->filesPerLine - ($this->checkedFiles % $this->filesPerLine);
$this->write(str_repeat(' ', $rest));
$this->writePercent();
}

$this->writeNewLine(2);
$this->writeNewLine(2);
}

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

protected function progress()
protected function writeMark($type)
{
++$this->checkedFiles;

if ($this->checkedFiles % $this->filesPerLine === 0) {
$this->writeProgress();
if ($this->showProgress) {
if ($type === self::TYPE_OK) {
$this->writer->write('.');

} elseif ($type === self::TYPE_SKIP) {
$this->write('S', self::TYPE_SKIP);

} elseif ($type === self::TYPE_ERROR) {
$this->write('X', self::TYPE_ERROR);

} elseif ($type === self::TYPE_FAIL) {
$this->writer->write('-');
}

if ($this->checkedFiles % $this->filesPerLine === 0) {
$this->writePercent();
}
}
}

protected function writeProgress()
protected function writePercent()
{
$percent = floor($this->checkedFiles / $this->totalFileCount * 100);
$current = $this->stringWidth($this->checkedFiles, strlen($this->totalFileCount));
Expand Down
12 changes: 11 additions & 1 deletion src/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class Settings
public $paths = array();

/**
* Dont't check files or directories
* Don't check files or directories
* @var array
*/
public $excluded = array();
Expand All @@ -88,6 +88,12 @@ class Settings
*/
public $colors = self::AUTODETECT;

/**
* Show progress in text output
* @var bool
*/
public $showProgress = true;

/**
* Output results as JSON string
* @var bool
Expand Down Expand Up @@ -174,6 +180,10 @@ public static function parseArguments(array $arguments)
$settings->colors = self::DISABLED;
break;

case '--no-progress':
$settings->showProgress = false;
break;

case '--json':
$settings->json = true;
break;
Expand Down
16 changes: 16 additions & 0 deletions tests/Settings.parseArguments.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class SettingsParseArgumentsTest extends Tester\TestCase
$expectedSettings->paths = array('.');
$expectedSettings->excluded = array();
$expectedSettings->colors = Settings::AUTODETECT;
$expectedSettings->showProgress = true;
$expectedSettings->json = false;

Assert::equal($expectedSettings->phpExecutable, $settings->phpExecutable);
Expand All @@ -36,6 +37,7 @@ class SettingsParseArgumentsTest extends Tester\TestCase
Assert::equal($expectedSettings->paths, $settings->paths);
Assert::equal($expectedSettings->excluded, $settings->excluded);
Assert::equal($expectedSettings->colors, $settings->colors);
Assert::equal($expectedSettings->showProgress, $settings->showProgress);
Assert::equal($expectedSettings->json, $settings->json);
}

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

Assert::equal($expectedSettings->phpExecutable, $settings->phpExecutable);
Expand All @@ -64,6 +67,7 @@ class SettingsParseArgumentsTest extends Tester\TestCase
Assert::equal($expectedSettings->paths, $settings->paths);
Assert::equal($expectedSettings->excluded, $settings->excluded);
Assert::equal($expectedSettings->colors, $settings->colors);
Assert::equal($expectedSettings->showProgress, $settings->showProgress);
Assert::equal($expectedSettings->json, $settings->json);
}

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

Assert::equal($expectedSettings->colors, $settings->colors);
}

public function testNoProgress()
{
$commandLine = "./parallel-lint --exclude vendor --no-progress .";
$argv = explode(" ", $commandLine);
$settings = Settings::parseArguments($argv);

$expectedSettings = new Settings();
$expectedSettings->showProgress = false;

Assert::equal($expectedSettings->colors, $settings->colors);
}
}

$testCase = new SettingsParseArgumentsTest;
Expand Down

0 comments on commit 6e0077a

Please sign in to comment.