1
0
Fork 0

Add json output for show command

pull/6228/head
Alexander Schwenn 2017-03-05 23:50:46 +01:00
parent 818687849d
commit c70aaa421d
1 changed files with 63 additions and 50 deletions

View File

@ -14,6 +14,7 @@ namespace Composer\Command;
use Composer\DependencyResolver\Pool;
use Composer\DependencyResolver\DefaultPolicy;
use Composer\Json\JsonFile;
use Composer\Package\CompletePackageInterface;
use Composer\Package\Version\VersionParser;
use Composer\Package\BasePackage;
@ -74,6 +75,7 @@ class ShowCommand extends BaseCommand
new InputOption('minor-only', 'm', InputOption::VALUE_NONE, 'Show only packages that have minor SemVer-compatible updates. Use with the --outdated option.'),
new InputOption('direct', 'D', InputOption::VALUE_NONE, 'Shows only packages that are directly required by the root package'),
new InputOption('strict', null, InputOption::VALUE_NONE, 'Return a non-zero exit code when there are outdated packages'),
new InputOption('format', 'f', InputOption::VALUE_REQUIRED, 'Format of the output: text or json', 'text'),
))
->setHelp(<<<EOT
The show command displays detailed information about a package, or
@ -114,6 +116,13 @@ EOT
return 1;
}
$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;
}
// init repos
$platformOverrides = array();
if ($composer) {
@ -378,6 +387,9 @@ EOT
}
}
if ('json' === $format) {
$io->write(JsonFile::encode($viewData));
} else {
foreach ($viewData as $type => $packages) {
$nameLength = $viewMetaData[$type]['nameLength'];
$versionLength = $viewMetaData[$type]['versionLength'];
@ -437,6 +449,7 @@ EOT
$io->write('');
}
}
}
return $exitCode;
}