Skip to content

Fix: Correctly Apply Symfony Output Flags #235

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions src/Console/Style/EasyCodingStandardStyleFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Symplify\EasyCodingStandard\Console\Style;

use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Terminal;
Expand All @@ -27,6 +28,8 @@ public function create(): EasyCodingStandardStyle
$argvInput = new ArgvInput();
$consoleOutput = new ConsoleOutput();

$this->applySymfonyConsoleArgs($argvInput, $consoleOutput);

// --debug is called
if ($argvInput->hasParameterOption('--debug')) {
$consoleOutput->setVerbosity(OutputInterface::VERBOSITY_DEBUG);
Expand All @@ -39,4 +42,36 @@ public function create(): EasyCodingStandardStyle

return new EasyCodingStandardStyle($argvInput, $consoleOutput, $this->terminal);
}

/**
* This method was derived from the `Application::configureIO` method of the Symfony Console
* component, under the MIT license. See NOTICE for the full license.
*
* @see https://github.com/symfony/console/blob/0aa29ca177f432ab68533432db0de059f39c92ae/Application.php#L905
*/
private function applySymfonyConsoleArgs(InputInterface $input, OutputInterface $output): void
{
$enableAnsi = $input->hasParameterOption(['--ansi'], true);
$disableAnsi = $input->hasParameterOption(['--no-ansi'], true);

match (true) {
$enableAnsi => $output->setDecorated(true),
$disableAnsi => $output->setDecorated(false),
default => null,
};

$enableQuiet = $input->hasParameterOption(['--quiet', '-q'], true);

$isVVV = $input->hasParameterOption('-vvv', true);
$isVV = $input->hasParameterOption('-vv', true);
$isV = $input->hasParameterOption('-v', true);

match (true) {
$enableQuiet => $output->setVerbosity(OutputInterface::VERBOSITY_QUIET),
$isVVV => $output->setVerbosity(OutputInterface::VERBOSITY_DEBUG),
$isVV => $output->setVerbosity(OutputInterface::VERBOSITY_VERY_VERBOSE),
$isV => $output->setVerbosity(OutputInterface::VERBOSITY_VERBOSE),
default => null,
};
}
}
35 changes: 35 additions & 0 deletions src/Console/Style/SymfonyStyleFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Symplify\EasyCodingStandard\Console\Style;

use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
Expand All @@ -24,6 +25,8 @@ public static function create(): SymfonyStyle
$argvInput = new ArgvInput();
$consoleOutput = new ConsoleOutput();

self::applySymfonyConsoleArgs($argvInput, $consoleOutput);

// --debug is called
if ($argvInput->hasParameterOption('--debug')) {
$consoleOutput->setVerbosity(OutputInterface::VERBOSITY_DEBUG);
Expand All @@ -44,4 +47,36 @@ private static function isPHPUnitRun(): bool
{
return defined('PHPUNIT_COMPOSER_INSTALL') || defined('__PHPUNIT_PHAR__');
}

/**
* This method was derived from the `Application::configureIO` method of the Symfony Console
* component, under the MIT license. See NOTICE for the full license.
*
* @see https://github.com/symfony/console/blob/0aa29ca177f432ab68533432db0de059f39c92ae/Application.php#L905
*/
private static function applySymfonyConsoleArgs(InputInterface $input, OutputInterface $output): void
{
$enableAnsi = $input->hasParameterOption(['--ansi'], true);
$disableAnsi = $input->hasParameterOption(['--no-ansi'], true);

match (true) {
$enableAnsi => $output->setDecorated(true),
$disableAnsi => $output->setDecorated(false),
default => null,
};

$enableQuiet = $input->hasParameterOption(['--quiet', '-q'], true);

$isVVV = $input->hasParameterOption('-vvv', true);
$isVV = $input->hasParameterOption('-vv', true);
$isV = $input->hasParameterOption('-v', true);

match (true) {
$enableQuiet => $output->setVerbosity(OutputInterface::VERBOSITY_QUIET),
$isVVV => $output->setVerbosity(OutputInterface::VERBOSITY_DEBUG),
$isVV => $output->setVerbosity(OutputInterface::VERBOSITY_VERY_VERBOSE),
$isV => $output->setVerbosity(OutputInterface::VERBOSITY_VERBOSE),
default => null,
};
}
}