Skip to content

Commit

Permalink
feat: remove Symfony/console dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
smeghead committed Mar 8, 2024
1 parent 80ed8ed commit 12329e9
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 27 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# CHANGELOG

## v0.0.5 (2024-03-08)

### Features

* remove Symfony/console dependency

### Bug fix

* Fixed message when missing required argument.
Expand Down
9 changes: 4 additions & 5 deletions bin/php-vendor-credits
Original file line number Diff line number Diff line change
Expand Up @@ -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();
$options = getopt('hvV', ['help', 'version'], $restIndex);

$command = new CreditsCommand('0.0.5');
$command->run($options, array_slice($argv, $restIndex));
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
}
],
"require": {
"php" : ">=7.4",
"symfony/console": "^5.4|^6.4"
"php" : ">=7.4"
},
"scripts": {
"test": [
Expand Down
52 changes: 37 additions & 15 deletions src/Command/CreditsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string|bool> $options
* @param array<string> $args
*/
public function run(array $options, array $args): void
{
$usage =<<<EOU
usage: php-vendor-credits [OPTIONS] <project directory>
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();

Expand All @@ -37,15 +59,15 @@ 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(),
$l->getUrl(),
$l->getContent()
), $licenses)));

return Command::SUCCESS;
return;
}

}
}
6 changes: 1 addition & 5 deletions test/integration/CreditsUsecaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

0 comments on commit 12329e9

Please sign in to comment.