From f3d32475a298324661a96856991fd74d00663da8 Mon Sep 17 00:00:00 2001 From: Ben Ramsey Date: Wed, 12 Aug 2020 19:09:37 -0500 Subject: [PATCH] feat: add conventional-commits console command --- bin/conventional-commits | 58 +++++++++++++++++++ composer.json | 3 + .../Console/Command/PrepareCommand.php | 7 ++- 3 files changed, 65 insertions(+), 3 deletions(-) create mode 100644 bin/conventional-commits diff --git a/bin/conventional-commits b/bin/conventional-commits new file mode 100644 index 0000000..0985c94 --- /dev/null +++ b/bin/conventional-commits @@ -0,0 +1,58 @@ +#!/usr/bin/env php + + * @license https://opensource.org/licenses/MIT MIT License + */ + +declare(strict_types=1); + +use Ramsey\ConventionalCommits\Console\Command\PrepareCommand; +use Symfony\Component\Console\Application; +use Symfony\Component\Console\Input\ArgvInput; + +(static function (array $argv): void { + $composerAutoloadLocations = [ + __DIR__ . '/../autoload.php', + __DIR__ . '/../vendor/autoload.php', + __DIR__ . '/../../../autoload.php', + ]; + + foreach ($composerAutoloadLocations as $file) { + if (file_exists($file)) { + $composerAutoloader = $file; + + break; + } + } + unset($file); + + if (!isset($composerAutoloader)) { + fwrite( + STDERR, + 'To execute this command, please install Composer and run \'composer install\'.' . PHP_EOL + . 'For more information, go to https://getcomposer.org' . PHP_EOL, + ); + + exit(1); + } + + require $composerAutoloader; + + $application = new Application('Conventional Commits'); + $application->add(new PrepareCommand()); + $application->run(new ArgvInput($argv)); +})($argv); diff --git a/composer.json b/composer.json index 4960e0b..296d34a 100644 --- a/composer.json +++ b/composer.json @@ -59,6 +59,9 @@ "vendor/hamcrest/hamcrest-php/hamcrest/Hamcrest.php" ] }, + "bin": [ + "bin/conventional-commits" + ], "scripts": { "post-autoload-dump": "captainhook install --ansi -f -s", "br:analyze": [ diff --git a/src/ConventionalCommits/Console/Command/PrepareCommand.php b/src/ConventionalCommits/Console/Command/PrepareCommand.php index 19e44bf..8b2baf0 100644 --- a/src/ConventionalCommits/Console/Command/PrepareCommand.php +++ b/src/ConventionalCommits/Console/Command/PrepareCommand.php @@ -76,10 +76,11 @@ public function getMessage(): ?Message protected function configure(): void { $this - ->setDescription('Prepares a commit message.') + ->setDescription('Prepares a commit message conforming to Conventional Commits') ->setHelp( - 'This command helps prepare a commit message according to the ' - . 'Conventional Commits specification.', + 'This command interactively helps prepare a commit message ' + . 'according to the Conventional Commits specification. For more ' + . 'information, see https://www.conventionalcommits.org.', ); }