* * This source file is subject to the MIT license that is bundled * with this source code in the file LICENSE. */ namespace Symfony\CS\Console\Command; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; /** * @author Fabien Potencier */ class ReadmeCommand extends Command { /** * @see Command */ protected function configure() { $this ->setName('readme') ->setDescription('Generates the README content, based on the fix command help') ; } /** * @see Command */ protected function execute(InputInterface $input, OutputInterface $output) { $header = <<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('##', '``', $help); $help = preg_replace('#^(\s+)``(.+)``$#m', '$1$2', $help); $help = preg_replace('#^ \* ``(.+)``#m', '* **$1**', $help); $help = preg_replace("#^\n( +)#m", "\n.. code-block:: bash\n\n$1", $help); $help = preg_replace("#^\.\. code-block:: bash\n\n( +<\?php)#m", ".. code-block:: php\n\n$1", $help); $help = preg_replace_callback( "#^\s*<\?php.*?\?>#ms", function ($matches) { return preg_replace("#\n\n +\?>#", '', preg_replace("#^\.\. code-block:: bash\n\n#m", '', $matches[0])); }, $help ); $help = preg_replace('#^ #m', ' ', $help); $help = preg_replace('#\*\* +\[#', '** [', $help); $output->write($header."\n".$help."\n".$footer); } }