mirror of https://github.com/rectorphp/rector.git
[console] add rector console output style with CI friendly progress bar redraw (#1793)
This commit is contained in:
parent
bc0eac36f4
commit
9953b6cab1
|
@ -60,7 +60,7 @@ jobs:
|
|||
- run: composer install --no-progress --ansi
|
||||
|
||||
## First run Rector - here can't be --dry-run !!! it would stop the job with it and not commit anything in the future
|
||||
- run: bin/rector process ${{ matrix.paths }} --ansi --no-progress-bar
|
||||
- run: bin/rector process ${{ matrix.paths }} --ansi
|
||||
|
||||
- run: vendor/bin/ecs check --fix --ansi
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ use Rector\ChangesReporting\Output\JsonOutputFormatter;
|
|||
use Rector\Core\Bootstrap\RectorConfigsResolver;
|
||||
use Rector\Core\Configuration\Option;
|
||||
use Rector\Core\Console\ConsoleApplication;
|
||||
use Rector\Core\Console\Style\SymfonyStyleFactory;
|
||||
use Rector\Core\Console\Style\RectorConsoleOutputStyleFactory;
|
||||
use Rector\Core\DependencyInjection\RectorContainerFactory;
|
||||
use Rector\Core\Kernel\RectorKernel;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
|
@ -59,9 +59,9 @@ try {
|
|||
]);
|
||||
} else {
|
||||
// report fatal errors in console format
|
||||
$symfonyStyleFactory = new SymfonyStyleFactory(new PrivatesCaller());
|
||||
$symfonyStyle = $symfonyStyleFactory->create();
|
||||
$symfonyStyle->error($throwable->getMessage());
|
||||
$rectorConsoleOutputStyleFactory = new RectorConsoleOutputStyleFactory(new PrivatesCaller());
|
||||
$rectorConsoleOutputStyle = $rectorConsoleOutputStyleFactory->create();
|
||||
$rectorConsoleOutputStyle->error($throwable->getMessage());
|
||||
}
|
||||
|
||||
exit(Command::FAILURE);
|
||||
|
|
|
@ -15,11 +15,13 @@
|
|||
"composer/xdebug-handler": "^2.0|^3.0",
|
||||
"doctrine/inflector": "^2.0",
|
||||
"ergebnis/json-printer": "^3.2",
|
||||
"helmich/typo3-typoscript-parser": "dev-master#0ccb3a6",
|
||||
"idiosyncratic/editorconfig": "^0.1.3",
|
||||
"myclabs/php-enum": "^1.8",
|
||||
"nette/neon": "^3.3.2",
|
||||
"nette/utils": "^3.2",
|
||||
"nikic/php-parser": "^4.13.2",
|
||||
"ondram/ci-detector": "^4.1",
|
||||
"phpstan/phpdoc-parser": "^1.2",
|
||||
"phpstan/phpstan": "^1.4.2",
|
||||
"phpstan/phpstan-phpunit": "^1.0",
|
||||
|
@ -46,7 +48,6 @@
|
|||
"symfony/string": "^6.0",
|
||||
"symfony/yaml": "^5.4|^6.0",
|
||||
"symplify/astral": "^10.0.16",
|
||||
"symplify/symplify-kernel": "^10.0.16",
|
||||
"symplify/autowire-array-parameter": "^10.0.16",
|
||||
"symplify/composer-json-manipulator": "^10.0.16",
|
||||
"symplify/console-color-diff": "^10.0.16",
|
||||
|
@ -57,10 +58,10 @@
|
|||
"symplify/skipper": "^10.0.16",
|
||||
"symplify/smart-file-system": "^10.0.16",
|
||||
"symplify/symfony-php-config": "^10.0.16",
|
||||
"symplify/symplify-kernel": "^10.0.16",
|
||||
"symplify/vendor-patches": "^10.0.16",
|
||||
"tracy/tracy": "^2.9",
|
||||
"webmozart/assert": "^1.10",
|
||||
"helmich/typo3-typoscript-parser": "dev-master#0ccb3a6"
|
||||
"webmozart/assert": "^1.10"
|
||||
},
|
||||
"require-dev": {
|
||||
"brianium/paratest": "^6.3",
|
||||
|
|
|
@ -28,6 +28,7 @@ use Rector\BetterPhpDocParser\PhpDocParser\BetterTypeParser;
|
|||
use Rector\Caching\Cache;
|
||||
use Rector\Caching\CacheFactory;
|
||||
use Rector\Core\Console\ConsoleApplication;
|
||||
use Rector\Core\Console\Style\RectorConsoleOutputStyleFactory;
|
||||
use Rector\Core\Validation\Collector\EmptyConfigurableRectorCollector;
|
||||
use Rector\NodeTypeResolver\DependencyInjection\PHPStanServicesFactory;
|
||||
use Rector\NodeTypeResolver\Reflection\BetterReflection\SourceLocator\IntermediateSourceLocator;
|
||||
|
@ -38,7 +39,6 @@ use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigura
|
|||
use function Symfony\Component\DependencyInjection\Loader\Configurator\service;
|
||||
use Symplify\Astral\NodeTraverser\SimpleCallableNodeTraverser;
|
||||
use Symplify\PackageBuilder\Console\Command\CommandNaming;
|
||||
use Symplify\PackageBuilder\Console\Style\SymfonyStyleFactory;
|
||||
use Symplify\PackageBuilder\Parameter\ParameterProvider;
|
||||
use Symplify\PackageBuilder\Php\TypeChecker;
|
||||
use Symplify\PackageBuilder\Reflection\PrivatesAccessor;
|
||||
|
@ -61,6 +61,7 @@ return static function (ContainerConfigurator $containerConfigurator): void {
|
|||
$services->load('Rector\Core\\', __DIR__ . '/../src')
|
||||
->exclude([
|
||||
__DIR__ . '/../src/Rector',
|
||||
__DIR__ . '/../src/Console/Style/RectorConsoleOutputStyle.php',
|
||||
__DIR__ . '/../src/Exception',
|
||||
__DIR__ . '/../src/DependencyInjection/CompilerPass',
|
||||
__DIR__ . '/../src/DependencyInjection/Loader',
|
||||
|
@ -89,6 +90,9 @@ return static function (ContainerConfigurator $containerConfigurator): void {
|
|||
$services->set(CloningVisitor::class);
|
||||
$services->set(NodeFinder::class);
|
||||
|
||||
$services->set(SymfonyStyle::class)
|
||||
->factory([service(RectorConsoleOutputStyleFactory::class), 'create']);
|
||||
|
||||
$services->set(Parser::class)
|
||||
->factory([service(PHPStanServicesFactory::class), 'createPHPStanParser']);
|
||||
|
||||
|
@ -109,10 +113,6 @@ return static function (ContainerConfigurator $containerConfigurator): void {
|
|||
|
||||
$services->set(StringFormatConverter::class);
|
||||
|
||||
$services->set(SymfonyStyleFactory::class);
|
||||
$services->set(SymfonyStyle::class)
|
||||
->factory([service(SymfonyStyleFactory::class), 'create']);
|
||||
|
||||
$services->set(JsonFileSystem::class);
|
||||
$services->set(NodeConnectingVisitor::class);
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ $autoloadFile = $projectRoot . '/vendor/autoload.php';
|
|||
// so we can use helper classes here
|
||||
require_once __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
$e2eCommand = 'php '. $rectorBin .' process --dry-run --no-ansi --no-progress-bar -a '. $autoloadFile . ' --clear-cache';
|
||||
$e2eCommand = 'php '. $rectorBin .' process --dry-run --no-ansi -a '. $autoloadFile . ' --clear-cache';
|
||||
|
||||
if (isset($argv[1]) && $argv[1] === '-c') {
|
||||
$e2eCommand .= ' -c ' . $argv[2];
|
||||
|
|
|
@ -4,7 +4,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace Rector\Core\Console\Command;
|
||||
|
||||
use Rector\Core\Contract\Console\OutputStyleInterface;
|
||||
use Rector\Core\Console\Output\RectorOutputStyle;
|
||||
use Rector\Core\Contract\Rector\RectorInterface;
|
||||
use Rector\PostRector\Contract\Rector\ComplementaryRectorInterface;
|
||||
use Rector\PostRector\Contract\Rector\PostRectorInterface;
|
||||
|
@ -19,7 +19,7 @@ final class ShowCommand extends Command
|
|||
* @param RectorInterface[] $rectors
|
||||
*/
|
||||
public function __construct(
|
||||
private readonly OutputStyleInterface $outputStyle,
|
||||
private readonly RectorOutputStyle $rectorOutputStyle,
|
||||
private readonly array $rectors
|
||||
) {
|
||||
parent::__construct();
|
||||
|
@ -33,7 +33,7 @@ final class ShowCommand extends Command
|
|||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$this->outputStyle->title('Loaded Rector rules');
|
||||
$this->rectorOutputStyle->title('Loaded Rector rules');
|
||||
|
||||
$rectors = array_filter(
|
||||
$this->rectors,
|
||||
|
@ -54,20 +54,20 @@ final class ShowCommand extends Command
|
|||
PHP_EOL . PHP_EOL,
|
||||
PHP_EOL
|
||||
);
|
||||
$this->outputStyle->warning($warningMessage);
|
||||
$this->rectorOutputStyle->warning($warningMessage);
|
||||
|
||||
return self::FAILURE;
|
||||
}
|
||||
|
||||
$rectorCount = count($rectors);
|
||||
foreach ($rectors as $rector) {
|
||||
$this->outputStyle->writeln(' * ' . $rector::class);
|
||||
$this->rectorOutputStyle->writeln(' * ' . $rector::class);
|
||||
}
|
||||
|
||||
$message = sprintf('%d loaded Rectors', $rectorCount);
|
||||
$this->outputStyle->success($message);
|
||||
$this->rectorOutputStyle->success($message);
|
||||
|
||||
$this->outputStyle->error(
|
||||
$this->rectorOutputStyle->error(
|
||||
'The "show" command is deprecated and will be removed, as it was used only for more output on Rector run. Use the "--debug" option and process command for debugging output instead.'
|
||||
);
|
||||
// to spot the error message
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Core\Console\Style;
|
||||
|
||||
use OndraM\CiDetector\CiDetector;
|
||||
use Symfony\Component\Console\Helper\ProgressBar;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
|
||||
final class RectorConsoleOutputStyle extends SymfonyStyle
|
||||
{
|
||||
private bool|null $isCiDetected = null;
|
||||
|
||||
/**
|
||||
* @see https://github.com/phpstan/phpstan-src/commit/0993d180e5a15a17631d525909356081be59ffeb
|
||||
*/
|
||||
public function createProgressBar(int $max = 0): ProgressBar
|
||||
{
|
||||
$progressBar = parent::createProgressBar($max);
|
||||
$progressBar->setOverwrite(! $this->isCiDetected());
|
||||
|
||||
$isCiDetected = $this->isCiDetected();
|
||||
$progressBar->setOverwrite(! $isCiDetected);
|
||||
|
||||
if ($isCiDetected) {
|
||||
$progressBar->minSecondsBetweenRedraws(15);
|
||||
$progressBar->maxSecondsBetweenRedraws(30);
|
||||
} elseif (DIRECTORY_SEPARATOR === '\\') {
|
||||
$progressBar->minSecondsBetweenRedraws(0.5);
|
||||
$progressBar->maxSecondsBetweenRedraws(2);
|
||||
} else {
|
||||
$progressBar->minSecondsBetweenRedraws(0.1);
|
||||
$progressBar->maxSecondsBetweenRedraws(0.5);
|
||||
}
|
||||
|
||||
return $progressBar;
|
||||
}
|
||||
|
||||
private function isCiDetected(): bool
|
||||
{
|
||||
if ($this->isCiDetected === null) {
|
||||
$ciDetector = new CiDetector();
|
||||
$this->isCiDetected = $ciDetector->isCiDetected();
|
||||
}
|
||||
|
||||
return $this->isCiDetected;
|
||||
}
|
||||
}
|
|
@ -8,17 +8,16 @@ use Symfony\Component\Console\Application;
|
|||
use Symfony\Component\Console\Input\ArgvInput;
|
||||
use Symfony\Component\Console\Output\ConsoleOutput;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
use Symplify\PackageBuilder\Reflection\PrivatesCaller;
|
||||
|
||||
final class SymfonyStyleFactory
|
||||
final class RectorConsoleOutputStyleFactory
|
||||
{
|
||||
public function __construct(
|
||||
private readonly PrivatesCaller $privatesCaller
|
||||
) {
|
||||
}
|
||||
|
||||
public function create(): SymfonyStyle
|
||||
public function create(): RectorConsoleOutputStyle
|
||||
{
|
||||
$argvInput = new ArgvInput();
|
||||
$consoleOutput = new ConsoleOutput();
|
||||
|
@ -32,6 +31,6 @@ final class SymfonyStyleFactory
|
|||
$consoleOutput->setVerbosity(OutputInterface::VERBOSITY_DEBUG);
|
||||
}
|
||||
|
||||
return new SymfonyStyle($argvInput, $consoleOutput);
|
||||
return new RectorConsoleOutputStyle($argvInput, $consoleOutput);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue