Browse Source

Add application version to \"fix\" out put when verbosity flag is set

SpacePossum 4 years ago
parent
commit
dae30a313c

+ 20 - 6
src/Console/Command/DescribeCommand.php

@@ -37,6 +37,7 @@ use Symfony\Component\Console\Command\Command;
 use Symfony\Component\Console\Formatter\OutputFormatter;
 use Symfony\Component\Console\Input\InputArgument;
 use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Output\ConsoleOutputInterface;
 use Symfony\Component\Console\Output\OutputInterface;
 
 /**
@@ -96,6 +97,12 @@ final class DescribeCommand extends Command
      */
     protected function execute(InputInterface $input, OutputInterface $output)
     {
+        if (OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity() && $output instanceof ConsoleOutputInterface) {
+            $stdErr = $output->getErrorOutput();
+            $stdErr->writeln($this->getApplication()->getLongVersion());
+            $stdErr->writeln(sprintf('Runtime: <info>PHP %s</info>', PHP_VERSION));
+        }
+
         $name = $input->getArgument('name');
 
         try {
@@ -139,6 +146,7 @@ final class DescribeCommand extends Command
 
         /** @var FixerInterface $fixer */
         $fixer = $fixers[$name];
+
         if ($fixer instanceof DefinedFixerInterface) {
             $definition = $fixer->getDefinition();
         } else {
@@ -146,6 +154,7 @@ final class DescribeCommand extends Command
         }
 
         $description = $definition->getSummary();
+
         if ($fixer instanceof DeprecatedFixerInterface) {
             $successors = $fixer->getSuccessorsNames();
             $message = [] === $successors
@@ -156,14 +165,17 @@ final class DescribeCommand extends Command
         }
 
         $output->writeln(sprintf('<info>Description of</info> %s <info>rule</info>.', $name));
+
         if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {
             $output->writeln(sprintf('Fixer class: <comment>%s</comment>.', \get_class($fixer)));
         }
 
         $output->writeln($description);
+
         if ($definition->getDescription()) {
             $output->writeln($definition->getDescription());
         }
+
         $output->writeln('');
 
         if ($fixer->isRisky()) {
@@ -184,8 +196,8 @@ final class DescribeCommand extends Command
 
             foreach ($options as $option) {
                 $line = '* <info>'.OutputFormatter::escape($option->getName()).'</info>';
-
                 $allowed = HelpCommand::getDisplayableAllowedValues($option);
+
                 if (null !== $allowed) {
                     foreach ($allowed as &$value) {
                         if ($value instanceof AllowedValueSubset) {
@@ -209,6 +221,7 @@ final class DescribeCommand extends Command
 
                 $description = Preg::replace('/(`.+?`)/', '<info>$1</info>', OutputFormatter::escape($option->getDescription()));
                 $line .= ': '.lcfirst(Preg::replace('/\.$/', '', $description)).'; ';
+
                 if ($option->hasDefault()) {
                     $line .= sprintf(
                         'defaults to <comment>%s</comment>',
@@ -225,6 +238,7 @@ final class DescribeCommand extends Command
                         OutputFormatter::escape(lcfirst($option->getDeprecationMessage()))
                     );
                 }
+
                 if ($option instanceof AliasedFixerOption) {
                     $line .= '; <error>DEPRECATED</error> alias: <comment>'.$option->getAlias().'</comment>';
                 }
@@ -302,8 +316,7 @@ final class DescribeCommand extends Command
                     $output->writeln(sprintf(' * Example #%d.', $index + 1));
                 }
 
-                $output->writeln($diffFormatter->format($diff, '   %s'));
-                $output->writeln('');
+                $output->writeln([$diffFormatter->format($diff, '   %s'), '']);
             }
         }
     }
@@ -321,7 +334,6 @@ final class DescribeCommand extends Command
         $fixers = $this->getFixers();
 
         $output->writeln(sprintf('<info>Description of the</info> %s <info>set.</info>', $ruleSetDefinitions[$name]->getName()));
-
         $output->writeln($this->replaceRstLinks($ruleSetDefinitions[$name]->getDescription()));
 
         if ($ruleSetDefinitions[$name]->isRisky()) {
@@ -378,6 +390,7 @@ final class DescribeCommand extends Command
         }
 
         $fixers = [];
+
         foreach ($this->fixerFactory->getFixers() as $fixer) {
             $fixers[$fixer->getName()] = $fixer;
         }
@@ -409,11 +422,11 @@ final class DescribeCommand extends Command
     {
         if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERY_VERBOSE) {
             $describe = [
-                'set' => $this->getSetNames(),
+                'sets' => $this->getSetNames(),
                 'rules' => $this->getFixers(),
             ];
         } elseif ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {
-            $describe = 'set' === $type ? ['set' => $this->getSetNames()] : ['rules' => $this->getFixers()];
+            $describe = 'set' === $type ? ['sets' => $this->getSetNames()] : ['rules' => $this->getFixers()];
         } else {
             return;
         }
@@ -421,6 +434,7 @@ final class DescribeCommand extends Command
         /** @var string[] $items */
         foreach ($describe as $list => $items) {
             $output->writeln(sprintf('<comment>Defined %s:</comment>', $list));
+
             foreach ($items as $name => $item) {
                 $output->writeln(sprintf('* <info>%s</info>', \is_string($name) ? $name : $item));
             }

+ 7 - 4
src/Console/Command/FixCommand.php

@@ -156,6 +156,11 @@ final class FixCommand extends Command
         ;
 
         if (null !== $stdErr) {
+            if (OutputInterface::VERBOSITY_VERBOSE <= $verbosity) {
+                $stdErr->writeln($this->getApplication()->getLongVersion());
+                $stdErr->writeln(sprintf('Runtime: <info>PHP %s</info>', PHP_VERSION));
+            }
+
             if (null !== $passedConfig && null !== $passedRules) {
                 if (getenv('PHP_CS_FIXER_FUTURE_MODE')) {
                     throw new \RuntimeException('Passing both `config` and `rules` options is not possible. This check was performed as `PHP_CS_FIXER_FUTURE_MODE` env var is set.');
@@ -169,12 +174,10 @@ final class FixCommand extends Command
 
             $configFile = $resolver->getConfigFile();
             $stdErr->writeln(sprintf('Loaded config <comment>%s</comment>%s.', $resolver->getConfig()->getName(), null === $configFile ? '' : ' from "'.$configFile.'"'));
-            if (OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) {
-                $stdErr->writeln(sprintf('Runtime: <info>PHP %s</info>', PHP_VERSION));
-            }
 
             if ($resolver->getUsingCache()) {
                 $cacheFile = $resolver->getCacheFile();
+
                 if (is_file($cacheFile)) {
                     $stdErr->writeln(sprintf('Using cache file "%s".', $cacheFile));
                 }
@@ -230,7 +233,7 @@ final class FixCommand extends Command
             $changed,
             $fixEvent->getDuration(),
             $fixEvent->getMemory(),
-            OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity(),
+            OutputInterface::VERBOSITY_VERBOSE <= $verbosity,
             $resolver->isDryRun(),
             $output->isDecorated()
         );

+ 15 - 8
src/Console/Command/SelfUpdateCommand.php

@@ -19,6 +19,7 @@ use PhpCsFixer\ToolInfoInterface;
 use Symfony\Component\Console\Command\Command;
 use Symfony\Component\Console\Input\InputInterface;
 use Symfony\Component\Console\Input\InputOption;
+use Symfony\Component\Console\Output\ConsoleOutputInterface;
 use Symfony\Component\Console\Output\OutputInterface;
 
 /**
@@ -92,6 +93,12 @@ EOT
      */
     protected function execute(InputInterface $input, OutputInterface $output)
     {
+        if (OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity() && $output instanceof ConsoleOutputInterface) {
+            $stdErr = $output->getErrorOutput();
+            $stdErr->writeln($this->getApplication()->getLongVersion());
+            $stdErr->writeln(sprintf('Runtime: <info>PHP %s</info>', PHP_VERSION));
+        }
+
         if (!$this->toolInfo->isInstalledAsPhar()) {
             $output->writeln('<error>Self-update is available only for PHAR version.</error>');
 
@@ -115,7 +122,7 @@ EOT
         }
 
         if (1 !== $this->versionChecker->compareVersions($latestVersion, $currentVersion)) {
-            $output->writeln('<info>php-cs-fixer is already up to date.</info>');
+            $output->writeln('<info>PHP CS Fixer is already up to date.</info>');
 
             return 0;
         }
@@ -126,13 +133,13 @@ EOT
             0 !== $this->versionChecker->compareVersions($latestVersionOfCurrentMajor, $latestVersion)
             && true !== $input->getOption('force')
         ) {
-            $output->writeln(sprintf('<info>A new major version of php-cs-fixer is available</info> (<comment>%s</comment>)', $latestVersion));
+            $output->writeln(sprintf('<info>A new major version of PHP CS Fixer is available</info> (<comment>%s</comment>)', $latestVersion));
             $output->writeln(sprintf('<info>Before upgrading please read</info> https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/%s/UPGRADE.md', $latestVersion));
             $output->writeln('<info>If you are ready to upgrade run this command with</info> <comment>-f</comment>');
             $output->writeln('<info>Checking for new minor/patch version...</info>');
 
             if (1 !== $this->versionChecker->compareVersions($latestVersionOfCurrentMajor, $currentVersion)) {
-                $output->writeln('<info>No minor update for php-cs-fixer.</info>');
+                $output->writeln('<info>No minor update for PHP CS Fixer.</info>');
 
                 return 0;
             }
@@ -143,7 +150,7 @@ EOT
         $localFilename = realpath($_SERVER['argv'][0]) ?: $_SERVER['argv'][0];
 
         if (!is_writable($localFilename)) {
-            $output->writeln(sprintf('<error>No permission to update %s file.</error>', $localFilename));
+            $output->writeln(sprintf('<error>No permission to update</error> "%s" <error>file.</error>', $localFilename));
 
             return 1;
         }
@@ -152,7 +159,7 @@ EOT
         $remoteFilename = $this->toolInfo->getPharDownloadUri($remoteTag);
 
         if (false === @copy($remoteFilename, $tempFilename)) {
-            $output->writeln(sprintf('<error>Unable to download new version %s from the server.</error>', $remoteTag));
+            $output->writeln(sprintf('<error>Unable to download new version</error> %s <error>from the server.</error>', $remoteTag));
 
             return 1;
         }
@@ -162,15 +169,15 @@ EOT
         $pharInvalidityReason = $this->pharChecker->checkFileValidity($tempFilename);
         if (null !== $pharInvalidityReason) {
             unlink($tempFilename);
-            $output->writeln(sprintf('<error>The download of %s is corrupt (%s).</error>', $remoteTag, $pharInvalidityReason));
-            $output->writeln('<error>Please re-run the self-update command to try again.</error>');
+            $output->writeln(sprintf('<error>The download of</error> %s <error>is corrupt (%s).</error>', $remoteTag, $pharInvalidityReason));
+            $output->writeln('<error>Please re-run the "self-update" command to try again.</error>');
 
             return 1;
         }
 
         rename($tempFilename, $localFilename);
 
-        $output->writeln(sprintf('<info>php-cs-fixer updated</info> (<comment>%s</comment>)', $remoteTag));
+        $output->writeln(sprintf('<info>PHP CS Fixer updated</info> (<comment>%s</comment> -> <comment>%s</comment>)', $currentVersion, $remoteTag));
 
         return 0;
     }

+ 8 - 7
tests/Console/Command/SelfUpdateCommandTest.php

@@ -140,6 +140,7 @@ final class SelfUpdateCommandTest extends TestCase
 
     public function provideExecuteCases()
     {
+        $currentVersion = Application::VERSION;
         $minor = $this->getNewMinorVersion();
         $major = $this->getNewMajorVersion();
 
@@ -147,23 +148,23 @@ final class SelfUpdateCommandTest extends TestCase
         $minorContents = 'New minor version of PHP CS Fixer.';
         $majorContents = 'New major version of PHP CS Fixer.';
 
-        $upToDateDisplay = "\033[32mphp-cs-fixer is already up to date.\033[39m\n";
-        $newMinorDisplay = "\033[32mphp-cs-fixer updated\033[39m (\033[33m{$minor}\033[39m)\n";
-        $newMajorDisplay = "\033[32mphp-cs-fixer updated\033[39m (\033[33m{$major}\033[39m)\n";
+        $upToDateDisplay = "\033[32mPHP CS Fixer is already up to date.\033[39m\n";
+        $newMinorDisplay = "\033[32mPHP CS Fixer updated\033[39m (\033[33m{$currentVersion}\033[39m -> \033[33m{$minor}\033[39m)\n";
+        $newMajorDisplay = "\033[32mPHP CS Fixer updated\033[39m (\033[33m{$currentVersion}\033[39m -> \033[33m{$major}\033[39m)\n";
         $majorInfoNoMinorDisplay = <<<OUTPUT
-\033[32mA new major version of php-cs-fixer is available\033[39m (\033[33m{$major}\033[39m)
+\033[32mA new major version of PHP CS Fixer is available\033[39m (\033[33m{$major}\033[39m)
 \033[32mBefore upgrading please read\033[39m https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/{$major}/UPGRADE.md
 \033[32mIf you are ready to upgrade run this command with\033[39m \033[33m-f\033[39m
 \033[32mChecking for new minor/patch version...\033[39m
-\033[32mNo minor update for php-cs-fixer.\033[39m
+\033[32mNo minor update for PHP CS Fixer.\033[39m
 
 OUTPUT;
         $majorInfoNewMinorDisplay = <<<OUTPUT
-\033[32mA new major version of php-cs-fixer is available\033[39m (\033[33m{$major}\033[39m)
+\033[32mA new major version of PHP CS Fixer is available\033[39m (\033[33m{$major}\033[39m)
 \033[32mBefore upgrading please read\033[39m https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/{$major}/UPGRADE.md
 \033[32mIf you are ready to upgrade run this command with\033[39m \033[33m-f\033[39m
 \033[32mChecking for new minor/patch version...\033[39m
-\033[32mphp-cs-fixer updated\033[39m (\033[33m{$minor}\033[39m)
+\033[32mPHP CS Fixer updated\033[39m (\033[33m{$currentVersion}\033[39m -> \033[33m{$minor}\033[39m)
 
 OUTPUT;
 

+ 4 - 2
tests/Smoke/CiIntegrationTest.php

@@ -14,6 +14,7 @@ namespace PhpCsFixer\Tests\Smoke;
 
 use Keradus\CliExecutor\CommandExecutor;
 use Keradus\CliExecutor\ScriptExecutor;
+use PhpCsFixer\Console\Application;
 
 /**
  * @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
@@ -148,11 +149,12 @@ If you need help while solving warnings, ask at https://gitter.im/PHP-CS-Fixer,
 ';
 
         $pattern = sprintf(
-            '/^(?:%s)?(?:%s)?%s\n(?:%s)([\.S]{%d})\n%s$/',
+            '/^(?:%s)?(?:%s)?%s\n%s\n%s\n([\.S]{%d})\n%s$/',
             preg_quote($optionalIncompatibilityWarning, '/'),
             preg_quote($optionalXdebugWarning, '/'),
+            'PHP CS Fixer '.preg_quote(Application::VERSION, '/').' '.preg_quote(Application::VERSION_CODENAME, '/').' by Fabien Potencier and Dariusz Ruminski',
+            preg_quote(sprintf('Runtime: PHP %s', PHP_VERSION), '/'),
             preg_quote('Loaded config default from ".php_cs.dist".', '/'),
-            preg_quote(sprintf("Runtime: PHP %s\n", PHP_VERSION), '/'),
             \strlen($expectedResult3Files),
             preg_quote('Legend: ?-unknown, I-invalid file syntax (file ignored), S-skipped (cached or empty file), .-no changes, F-fixed, E-error', '/')
         );