Add --format option to `composer fund` command (#9678)
* Add --format option to `composer fund` command Co-authored-by: Jochen Roth <jochen.roth@b13.com>pull/9542/head
parent
7c555b6382
commit
91b6ff27ac
|
@ -12,12 +12,14 @@
|
||||||
|
|
||||||
namespace Composer\Command;
|
namespace Composer\Command;
|
||||||
|
|
||||||
use Composer\Package\CompletePackageInterface;
|
use Composer\Json\JsonFile;
|
||||||
use Composer\Package\AliasPackage;
|
use Composer\Package\AliasPackage;
|
||||||
use Composer\Package\BasePackage;
|
use Composer\Package\BasePackage;
|
||||||
use Composer\Semver\Constraint\MatchAllConstraint;
|
use Composer\Package\CompletePackageInterface;
|
||||||
use Composer\Repository\CompositeRepository;
|
use Composer\Repository\CompositeRepository;
|
||||||
|
use Composer\Semver\Constraint\MatchAllConstraint;
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
|
use Symfony\Component\Console\Input\InputOption;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -30,6 +32,9 @@ class FundCommand extends BaseCommand
|
||||||
{
|
{
|
||||||
$this->setName('fund')
|
$this->setName('fund')
|
||||||
->setDescription('Discover how to help fund the maintenance of your dependencies.')
|
->setDescription('Discover how to help fund the maintenance of your dependencies.')
|
||||||
|
->setDefinition(array(
|
||||||
|
new InputOption('format', 'f', InputOption::VALUE_REQUIRED, 'Format of the output: text or json', 'text')
|
||||||
|
))
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,7 +86,14 @@ class FundCommand extends BaseCommand
|
||||||
|
|
||||||
$io = $this->getIO();
|
$io = $this->getIO();
|
||||||
|
|
||||||
if ($fundings) {
|
$format = $input->getOption('format');
|
||||||
|
if (!in_array($format, array('text', 'json'))) {
|
||||||
|
$io->writeError(sprintf('Unsupported format "%s". See help for supported formats.', $format));
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($fundings && $format === 'text') {
|
||||||
$prev = null;
|
$prev = null;
|
||||||
|
|
||||||
$io->write('The following packages were found in your dependencies which publish funding information:');
|
$io->write('The following packages were found in your dependencies which publish funding information:');
|
||||||
|
@ -104,6 +116,8 @@ class FundCommand extends BaseCommand
|
||||||
$io->write("");
|
$io->write("");
|
||||||
$io->write("Please consider following these links and sponsoring the work of package authors!");
|
$io->write("Please consider following these links and sponsoring the work of package authors!");
|
||||||
$io->write("Thank you!");
|
$io->write("Thank you!");
|
||||||
|
} elseif ($format === 'json') {
|
||||||
|
$io->write(JsonFile::encode($fundings));
|
||||||
} else {
|
} else {
|
||||||
$io->write("No funding links were found in your package dependencies. This doesn't mean they don't need your support!");
|
$io->write("No funding links were found in your package dependencies. This doesn't mean they don't need your support!");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue