1
0
Fork 0

Add new summary format for licenses (#8973)

* Add new summary format to render the number of dependencies for each used license

* Array dereferencing wasn't available on php 5.3

* Add summary format to documentation
pull/8982/head
Jonas Drieghe 2020-06-16 10:07:53 +02:00 committed by GitHub
parent d906ff12c9
commit 8da2811dc3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 1 deletions

View File

@ -785,7 +785,7 @@ Lists the name, version and license of every package installed. Use
### Options ### Options
* **--format:** Format of the output: text or json (default: "text") * **--format:** Format of the output: text, json or summary (default: "text")
* **--no-dev:** Remove dev dependencies from the output * **--no-dev:** Remove dev dependencies from the output
## run-script ## run-script

View File

@ -21,6 +21,7 @@ use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
/** /**
* @author Benoît Merlet <benoit.merlet@gmail.com> * @author Benoît Merlet <benoit.merlet@gmail.com>
@ -111,6 +112,28 @@ EOT
))); )));
break; break;
case 'summary':
$dependencies = array();
foreach ($packages as $package) {
$license = $package->getLicense();
$licenseName = $license[0];
if (!isset($dependencies[$licenseName])) {
$dependencies[$licenseName] = 0;
}
$dependencies[$licenseName]++;
}
$rows = array();
foreach ($dependencies as $usedLicense => $numberOfDependencies) {
$rows[] = array($usedLicense, $numberOfDependencies);
}
$symfonyIo = new SymfonyStyle($input, $output);
$symfonyIo->table(
array('License', 'Number of dependencies'),
$rows
);
break;
default: default:
throw new \RuntimeException(sprintf('Unsupported format "%s". See help for supported formats.', $format)); throw new \RuntimeException(sprintf('Unsupported format "%s". See help for supported formats.', $format));
} }