diff --git a/tools/phar/bin/jolitypo b/tools/phar/bin/jolitypo index 99125a7..3cb5e7b 100755 --- a/tools/phar/bin/jolitypo +++ b/tools/phar/bin/jolitypo @@ -13,11 +13,49 @@ use Symfony\Component\Finder\Finder; require __DIR__ . '/../vendor/autoload.php'; require __DIR__ . '/../../../vendor/autoload.php'; +$help = <<%command.name% --list-rules foo bar + +## Run the fixer on one file + +%command.name% fr_FR index.html + +## Run the fixer on one directory + +%command.name% fr_FR directory/ + +## Specify some rules: + +%command.name% fr_FR index.html --rule=FrenchQuotes --rule=Dash + +EOTXT; + (new SingleCommandApplication('JoliTypo')) ->addArgument('locale', InputArgument::REQUIRED, 'Locale of the content to fix.') ->addArgument('path', InputArgument::REQUIRED, 'Path of file(s) to fix.') ->addOption('rule', null, InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED, 'Rules used to fix the content') + ->addOption('list-rules', null, InputOption::VALUE_NONE, 'List available rules') + ->setHelp($help) ->setCode(function (InputInterface $input, OutputInterface $output): int { + $io = new SymfonyStyle($input, $output); + + if ($input->getOption('list-rules')) { + $list = []; + foreach ((new Finder())->in(__DIR__ . '/../../../src/JoliTypo/Fixer')->sortByName()->files() as $file) { + $list[] = $file->getFilenameWithoutExtension(); + } + $io->listing($list); + + return 0; + } + static $recommendedRulesByLocale = [ 'en_GB' => ['Ellipsis', 'Dimension', 'Unit', 'Dash', 'SmartQuotes', 'NoSpaceBeforeComma', 'CurlyQuote', 'Hyphen', 'Trademark'], 'fr_FR' => ['Ellipsis', 'Dimension', 'Unit', 'Dash', 'SmartQuotes', 'FrenchNoBreakSpace', 'NoSpaceBeforeComma', 'CurlyQuote', 'Hyphen', 'Trademark'], @@ -37,7 +75,6 @@ require __DIR__ . '/../../../vendor/autoload.php'; $rules = $recommendedRulesByLocale[$locale]; } - $io = new SymfonyStyle($input, $output); $fixer = new Fixer($rules); $fixer->setLocale($locale);