ReadmeCommand.php 8.32 KB
* Dariusz Rumiński * * This source file is subject to the MIT license that is bundled * with this source code in the file LICENSE. */ namespace PhpCsFixer\Console\Command; use PhpCsFixer\Preg; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; /** * @author Fabien Potencier * @author Dariusz Rumiński * * @internal */ final class ReadmeCommand extends Command { const COMMAND_NAME = 'readme'; /** * {@inheritdoc} */ protected function configure() { $this ->setName(self::COMMAND_NAME) ->setDescription('Generates the README content, based on the fix command help.') ; } /** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $header = <<`_ and issue the following command: .. code-block:: bash $ composer global require friendsofphp/php-cs-fixer Then make sure you have the global Composer binaries directory in your ``PATH``. This directory is platform-dependent, see `Composer documentation `_ for details. Example for some Unix systems: .. code-block:: bash $ export PATH="$PATH:$HOME/.composer/vendor/bin" Globally (homebrew) ~~~~~~~~~~~~~~~~~~~ .. code-block:: bash $ brew install php-cs-fixer Locally (PHIVE) ~~~~~~~~~~~~~~~ Install `PHIVE `_ and issue the following command: .. code-block:: bash $ phive install php-cs-fixer # use `--global` for global install Update ------ Locally ~~~~~~~ The ``self-update`` command tries to update ``php-cs-fixer`` itself: .. code-block:: bash $ php php-cs-fixer.phar self-update Globally (manual) ~~~~~~~~~~~~~~~~~ You can update ``php-cs-fixer`` through this command: .. code-block:: bash $ sudo php-cs-fixer self-update Globally (Composer) ~~~~~~~~~~~~~~~~~~~ You can update ``php-cs-fixer`` through this command: .. code-block:: bash $ ./composer.phar global update friendsofphp/php-cs-fixer Globally (homebrew) ~~~~~~~~~~~~~~~~~~~ You can update ``php-cs-fixer`` through this command: .. code-block:: bash $ brew upgrade php-cs-fixer Locally (PHIVE) ~~~~~~~~~~~~~~~~~~~ .. code-block:: bash $ phive update php-cs-fixer Usage ----- EOF; $footer = <<getApplication()->get('fix'); $help = $command->getHelp(); $help = str_replace('%command.full_name%', 'php-cs-fixer.phar '.$command->getName(), $help); $help = str_replace('%command.name%', $command->getName(), $help); $help = Preg::replace('#?(comment|info)>#', '``', $help); $help = Preg::replace('#`(``.+?``)`#', '$1', $help); $help = Preg::replace('#^(\s+)``(.+)``$#m', '$1$2', $help); $help = Preg::replace('#^ \* ``(.+)``(.*?\n)#m', "* **$1**$2\n", $help); $help = Preg::replace('#^ \\| #m', ' ', $help); $help = Preg::replace('#^ \\|#m', '', $help); $help = Preg::replace('#^(?= \\*Risky rule: )#m', "\n", $help); $help = Preg::replace("#^( Configuration options:\n)( - )#m", "$1\n$2", $help); $help = Preg::replace("#^\n( +\\$ )#m", "\n.. code-block:: bash\n\n$1", $help); $help = Preg::replace("#^\n( +#ms', static function ($matches) { $result = Preg::replace("#^\\.\\. code-block:: bash\n\n#m", '', $matches[0]); if ('php' !== $matches[1]) { $result = Preg::replace("##", '', $result); }, $help ); // Transform links // In the console output these have the form // `description` (http://...) // Make to RST http://www.sphinx-doc.org/en/stable/rest.html#hyperlinks // `description `_ $help = Preg::replaceCallback( '#`(.+)`\s?\((.+)\)#', static function (array $matches) { return sprintf('`%s `_', str_replace('\\', '\\\\', $matches[1]), $matches[2]); }, $help ); $help = Preg::replace('#^ #m', ' ', $help); $help = Preg::replace('#\*\* +\[#', '** [', $help); $downloadLatestUrl = sprintf('https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/download/v%s/php-cs-fixer.phar', HelpCommand::getLatestReleaseVersionFromChangeLog()); $downloadUrl = 'https://cs.symfony.com/download/php-cs-fixer-v2.phar'; $header = str_replace('%download.version_url%', $downloadLatestUrl, $header); $header = str_replace('%download.url%', $downloadUrl, $header); $footer = str_replace('%download.version_url%', $downloadLatestUrl, $footer); $footer = str_replace('%download.url%', $downloadUrl, $footer); $output->write($header."\n".$help."\n".$footer); } }