CheckPlatformReqs: Add json format output (#10979)
Co-authored-by: Jordi Boggiano <j.boggiano@seld.be>pull/10996/head
parent
e82050b05d
commit
058beef20a
|
@ -413,6 +413,12 @@ Unlike update/install, this command will ignore config.platform settings and
|
||||||
check the real platform packages so you can be certain you have the required
|
check the real platform packages so you can be certain you have the required
|
||||||
platform dependencies.
|
platform dependencies.
|
||||||
|
|
||||||
|
### Options
|
||||||
|
|
||||||
|
* **--lock:** Checks requirements only from the lock file, not from installed packages.
|
||||||
|
* **--no-dev:** Disables checking of require-dev packages requirements.
|
||||||
|
* **--format (-f):** Format of the output: text (default) or json
|
||||||
|
|
||||||
## global
|
## global
|
||||||
|
|
||||||
The global command allows you to run other commands like `install`, `remove`, `require`
|
The global command allows you to run other commands like `install`, `remove`, `require`
|
||||||
|
|
|
@ -15,11 +15,12 @@ namespace Composer\Command;
|
||||||
use Composer\Package\Link;
|
use Composer\Package\Link;
|
||||||
use Composer\Semver\Constraint\Constraint;
|
use Composer\Semver\Constraint\Constraint;
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Input\InputOption;
|
use Composer\Console\Input\InputOption;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
use Composer\Repository\PlatformRepository;
|
use Composer\Repository\PlatformRepository;
|
||||||
use Composer\Repository\RootPackageRepository;
|
use Composer\Repository\RootPackageRepository;
|
||||||
use Composer\Repository\InstalledRepository;
|
use Composer\Repository\InstalledRepository;
|
||||||
|
use Composer\Json\JsonFile;
|
||||||
|
|
||||||
class CheckPlatformReqsCommand extends BaseCommand
|
class CheckPlatformReqsCommand extends BaseCommand
|
||||||
{
|
{
|
||||||
|
@ -33,6 +34,7 @@ class CheckPlatformReqsCommand extends BaseCommand
|
||||||
->setDefinition(array(
|
->setDefinition(array(
|
||||||
new InputOption('no-dev', null, InputOption::VALUE_NONE, 'Disables checking of require-dev packages requirements.'),
|
new InputOption('no-dev', null, InputOption::VALUE_NONE, 'Disables checking of require-dev packages requirements.'),
|
||||||
new InputOption('lock', null, InputOption::VALUE_NONE, 'Checks requirements only from the lock file, not from installed packages.'),
|
new InputOption('lock', null, InputOption::VALUE_NONE, 'Checks requirements only from the lock file, not from installed packages.'),
|
||||||
|
new InputOption('format', 'f', InputOption::VALUE_REQUIRED, 'Format of the output: text or json', 'text', ['json', 'text']),
|
||||||
))
|
))
|
||||||
->setHelp(
|
->setHelp(
|
||||||
<<<EOT
|
<<<EOT
|
||||||
|
@ -127,7 +129,8 @@ EOT
|
||||||
$candidate->getName() === $require ? $candidate->getPrettyName() : $require,
|
$candidate->getName() === $require ? $candidate->getPrettyName() : $require,
|
||||||
$candidateConstraint->getPrettyString(),
|
$candidateConstraint->getPrettyString(),
|
||||||
$link,
|
$link,
|
||||||
'<error>failed</error>'.($candidate->getName() === $require ? '' : ' <comment>provided by '.$candidate->getPrettyName().'</comment>'),
|
'<error>failed</error>',
|
||||||
|
$candidate->getName() === $require ? '' : '<comment>provided by '.$candidate->getPrettyName().'</comment>',
|
||||||
);
|
);
|
||||||
|
|
||||||
// skip to next candidate
|
// skip to next candidate
|
||||||
|
@ -139,7 +142,8 @@ EOT
|
||||||
$candidate->getName() === $require ? $candidate->getPrettyName() : $require,
|
$candidate->getName() === $require ? $candidate->getPrettyName() : $require,
|
||||||
$candidateConstraint->getPrettyString(),
|
$candidateConstraint->getPrettyString(),
|
||||||
null,
|
null,
|
||||||
'<info>success</info>'.($candidate->getName() === $require ? '' : ' <comment>provided by '.$candidate->getPrettyName().'</comment>'),
|
'<info>success</info>',
|
||||||
|
$candidate->getName() === $require ? '' : '<comment>provided by '.$candidate->getPrettyName().'</comment>',
|
||||||
);
|
);
|
||||||
|
|
||||||
// candidate matched, skip to next requirement
|
// candidate matched, skip to next requirement
|
||||||
|
@ -158,13 +162,14 @@ EOT
|
||||||
'n/a',
|
'n/a',
|
||||||
$links[0],
|
$links[0],
|
||||||
'<error>missing</error>',
|
'<error>missing</error>',
|
||||||
|
'',
|
||||||
);
|
);
|
||||||
|
|
||||||
$exitCode = max($exitCode, 2);
|
$exitCode = max($exitCode, 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->printTable($output, $results);
|
$this->printTable($output, $results, $input->getOption('format'));
|
||||||
|
|
||||||
return $exitCode;
|
return $exitCode;
|
||||||
}
|
}
|
||||||
|
@ -174,22 +179,43 @@ EOT
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
protected function printTable(OutputInterface $output, array $results): void
|
protected function printTable(OutputInterface $output, array $results, string $format): void
|
||||||
{
|
{
|
||||||
$rows = array();
|
$rows = array();
|
||||||
foreach ($results as $result) {
|
foreach ($results as $result) {
|
||||||
/**
|
/**
|
||||||
* @var Link|null $link
|
* @var Link|null $link
|
||||||
*/
|
*/
|
||||||
list($platformPackage, $version, $link, $status) = $result;
|
list($platformPackage, $version, $link, $status, $provider) = $result;
|
||||||
$rows[] = array(
|
|
||||||
$platformPackage,
|
if ('json' === $format) {
|
||||||
$version,
|
$rows[] = array(
|
||||||
$link ? sprintf('%s %s %s (%s)', $link->getSource(), $link->getDescription(), $link->getTarget(), $link->getPrettyConstraint()) : '',
|
"name" => $platformPackage,
|
||||||
$status,
|
"version" => $version,
|
||||||
);
|
"status" => strip_tags($status),
|
||||||
|
"failed_requirement" => $link instanceof Link ? [
|
||||||
|
'source' => $link->getSource(),
|
||||||
|
'type' => $link->getDescription(),
|
||||||
|
'target' => $link->getTarget(),
|
||||||
|
'constraint' => $link->getPrettyConstraint(),
|
||||||
|
] : null,
|
||||||
|
"provider" => $provider === '' ? null : strip_tags($provider),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
$rows[] = array(
|
||||||
|
$platformPackage,
|
||||||
|
$version,
|
||||||
|
$link,
|
||||||
|
$link ? sprintf('%s %s %s (%s)', $link->getSource(), $link->getDescription(), $link->getTarget(), $link->getPrettyConstraint()) : '',
|
||||||
|
rtrim($status.' '.$provider),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->renderTable($rows, $output);
|
if ('json' === $format) {
|
||||||
|
$this->getIO()->write(JsonFile::encode($rows));
|
||||||
|
} else {
|
||||||
|
$this->renderTable($rows, $output);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue