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
main
Jonas Drieghe 4 years ago committed by GitHub
parent d906ff12c9
commit 8da2811dc3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -785,7 +785,7 @@ Lists the name, version and license of every package installed. Use
### 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
## run-script

@ -21,6 +21,7 @@ use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
/**
* @author Benoît Merlet <benoit.merlet@gmail.com>
@ -111,6 +112,28 @@ EOT
)));
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:
throw new \RuntimeException(sprintf('Unsupported format "%s". See help for supported formats.', $format));
}

Loading…
Cancel
Save