diff --git a/CHANGELOG.md b/CHANGELOG.md index 2e76250..0866d78 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # CHANGELOG +## v0.0.5 (2024-03-08) + +### Features + + * remove Symfony/console dependency + ### Bug fix * Fixed message when missing required argument. diff --git a/bin/php-vendor-credits b/bin/php-vendor-credits index 5eb4d87..7b76852 100755 --- a/bin/php-vendor-credits +++ b/bin/php-vendor-credits @@ -11,9 +11,8 @@ foreach ([__DIR__ . '/../../../autoload.php', __DIR__ . '/../vendor/autoload.php } use Smeghead\PhpVendorCredits\Command\CreditsCommand; -use Symfony\Component\Console\Application; -$app = new Application('php-vendor-credits', '0.0.4'); -$app->add(new CreditsCommand('php-vendor-credits')); -$app->setDefaultCommand('php-vendor-credits', true); -$app->run(); \ No newline at end of file +$options = getopt('hvV', ['help', 'version'], $restIndex); + +$command = new CreditsCommand('0.0.5'); +$command->run($options, array_slice($argv, $restIndex)); diff --git a/composer.json b/composer.json index af34af2..8b6d7b3 100644 --- a/composer.json +++ b/composer.json @@ -18,8 +18,7 @@ } ], "require": { - "php" : ">=7.4", - "symfony/console": "^5.4|^6.4" + "php" : ">=7.4" }, "scripts": { "test": [ diff --git a/src/Command/CreditsCommand.php b/src/Command/CreditsCommand.php index e6ad688..c821a07 100644 --- a/src/Command/CreditsCommand.php +++ b/src/Command/CreditsCommand.php @@ -6,26 +6,48 @@ use Smeghead\PhpVendorCredits\Lib\Usecase\CreditsUsecase; use Smeghead\PhpVendorCredits\Lib\Usecase\License; -use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Input\InputArgument; -use Symfony\Component\Console\Input\InputInterface; -use Symfony\Component\Console\Output\OutputInterface; -final class CreditsCommand extends Command +final class CreditsCommand { - protected static $defaultName = 'credits'; + private string $version; - protected function configure(): void + public function __construct(string $version) { - $this - ->setDescription('php-vendor-creadits creates CREDITS file from LICENSE files of dependencies') - ->addArgument('project directory', InputArgument::REQUIRED, 'Specify the directory where `composer.lock` exists.'); + $this->version = $version; } - protected function execute(InputInterface $input, OutputInterface $output): int + /** + * @param array $options + * @param array $args + */ + public function run(array $options, array $args): void { + $usage =<< + +php-vendor-creadits creates CREDITS file from LICENSE files of dependencies + +OPTIONS + -h, --help show this help page. + -v,-V, --version show version. + +EOU; + + if (isset($options['v']) || isset($options['V']) || isset($options['version'])) { + fputs(STDERR, sprintf('php-vendor-creates %s%s', $this->version, PHP_EOL)); + exit(-1); + } + if (isset($options['h']) || isset($options['help'])) { + fputs(STDERR, $usage); + exit(-1); + } + /** @var string|null */ - $rootDirectory = $input->getArgument('project directory'); + $rootDirectory = array_shift($args); + if (empty($rootDirectory)) { + fputs(STDERR, "ERROR: required project directory.\n"); + exit(-1); + } $usecase = new CreditsUsecase(strval($rootDirectory)); $licenses = $usecase->execute(); @@ -37,7 +59,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int ================================================================ EOC; - $output->write(implode("\n", array_map( + print(implode("\n", array_map( fn(License $l) => sprintf( $format, $l->getName(), @@ -45,7 +67,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $l->getContent() ), $licenses))); - return Command::SUCCESS; + return; } -} \ No newline at end of file +} diff --git a/test/integration/CreditsUsecaseTest.php b/test/integration/CreditsUsecaseTest.php index b081d6d..02622e1 100644 --- a/test/integration/CreditsUsecaseTest.php +++ b/test/integration/CreditsUsecaseTest.php @@ -13,10 +13,6 @@ public function testThisProject(): void $licenses = $sut->execute(); - $this->assertSame('psr/container', $licenses[0]->getName()); - $this->assertSame('https://github.com/php-fig/container', $licenses[0]->getUrl()); - $this->assertMatchesRegularExpression('@/vendor/psr/container/LICENSE$@', $licenses[0]->getPath()); - $this->assertMatchesRegularExpression('/Copyright \(c\) 2013-2016 container-interop/', $licenses[0]->getContent()); - $this->assertMatchesRegularExpression('/Copyright \(c\) 2016 PHP Framework Interoperability Group/', $licenses[0]->getContent()); + $this->assertSame(0, count($licenses)); } }