1
0
Fork 0

Undo some invalid merges and simplify code a little bit, refs #2600

pull/4647/head
Jordi Boggiano 2015-11-27 00:38:37 +00:00
parent a79d0ab886
commit 92ad33d11e
1 changed files with 44 additions and 43 deletions

View File

@ -19,6 +19,7 @@ use Composer\Package\CompletePackageInterface;
use Composer\Semver\VersionParser; use Composer\Semver\VersionParser;
use Composer\Plugin\CommandEvent; use Composer\Plugin\CommandEvent;
use Composer\Plugin\PluginEvents; use Composer\Plugin\PluginEvents;
use Composer\Package\PackageInterface;
use Symfony\Component\Console\Formatter\OutputFormatterStyle; use Symfony\Component\Console\Formatter\OutputFormatterStyle;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputArgument;
@ -70,7 +71,9 @@ EOT
protected function execute(InputInterface $input, OutputInterface $output) protected function execute(InputInterface $input, OutputInterface $output)
{ {
$this->versionParser = new VersionParser; $this->versionParser = new VersionParser;
if ($input->getOption('tree')) {
$this->initStyles($output); $this->initStyles($output);
}
// init repos // init repos
$platformRepo = new PlatformRepository; $platformRepo = new PlatformRepository;
@ -104,10 +107,6 @@ EOT
$repos = new CompositeRepository(array_merge(array($installedRepo), $defaultRepos)); $repos = new CompositeRepository(array_merge(array($installedRepo), $defaultRepos));
} }
if ($input->getOption('tree')) {
$repos = new CompositeRepository(array_merge(array($installedRepo), $composer->getRepositoryManager()->getRepositories()));
}
if ($composer) { if ($composer) {
$commandEvent = new CommandEvent(PluginEvents::COMMAND, 'show', $input, $output); $commandEvent = new CommandEvent(PluginEvents::COMMAND, 'show', $input, $output);
$composer->getEventDispatcher()->dispatch($commandEvent->getName(), $commandEvent); $composer->getEventDispatcher()->dispatch($commandEvent->getName(), $commandEvent);
@ -142,23 +141,33 @@ EOT
$this->printLinks($package, 'conflicts'); $this->printLinks($package, 'conflicts');
$this->printLinks($package, 'replaces'); $this->printLinks($package, 'replaces');
} }
$this->printLinks($package, 'provides');
$this->printLinks($package, 'conflicts');
$this->printLinks($package, 'replaces');
return; return;
} }
// list packages // show tree view if requested
$packages = array(); if ($input->getOption('tree')) {
if (!$input->getOption('installed')) {
$io->writeError('The --tree (-t) option is only usable in combination with --installed (-t) or by passing a single package name to show');
return 1;
}
foreach ($installedRepo->getPackages() as $package) {
$this->displayPackageTree($package, $installedRepo, $repos, $output);
}
return 0;
}
$allRepos = $repos;
if ($repos instanceof CompositeRepository) { if ($repos instanceof CompositeRepository) {
$repos = $repos->getRepositories(); $repos = $repos->getRepositories();
} elseif (!is_array($repos)) { } elseif (!is_array($repos)) {
$repos = array($repos); $repos = array($repos);
} }
// list packages
$packages = array();
foreach ($repos as $repo) { foreach ($repos as $repo) {
if ($repo === $platformRepo) { if ($repo === $platformRepo) {
$type = '<info>platform</info>:'; $type = '<info>platform</info>:';
@ -186,11 +195,11 @@ EOT
} }
} }
$tree = !$input->getOption('platform') && !$input->getOption('installed') && !$input->getOption('available'); $showAllTypes = !$input->getOption('platform') && !$input->getOption('installed') && !$input->getOption('available');
$indent = $tree && $input->getOption('installed') ? ' ' : ''; $indent = $showAllTypes ? ' ' : '';
foreach (array('<info>platform</info>:' => true, '<comment>available</comment>:' => false, '<info>installed</info>:' => true) as $type => $showVersion) { foreach (array('<info>platform</info>:' => true, '<comment>available</comment>:' => false, '<info>installed</info>:' => true) as $type => $showVersion) {
if (isset($packages[$type])) { if (isset($packages[$type])) {
if ($tree) { if ($showAllTypes) {
$io->write($type); $io->write($type);
} }
ksort($packages[$type]); ksort($packages[$type]);
@ -223,9 +232,6 @@ EOT
$writeVersion = !$input->getOption('name-only') && !$input->getOption('path') && $showVersion && ($nameLength + $versionLength + 3 <= $width); $writeVersion = !$input->getOption('name-only') && !$input->getOption('path') && $showVersion && ($nameLength + $versionLength + 3 <= $width);
$writeDescription = !$input->getOption('name-only') && !$input->getOption('path') && ($nameLength + ($showVersion ? $versionLength : 0) + 24 <= $width); $writeDescription = !$input->getOption('name-only') && !$input->getOption('path') && ($nameLength + ($showVersion ? $versionLength : 0) + 24 <= $width);
foreach ($packages[$type] as $package) { foreach ($packages[$type] as $package) {
if ($input->getOption('tree') && $input->getOption('installed')) {
$this->displayPackageTree($package, $installedRepo, $allRepos, $output);
} else {
if (is_object($package)) { if (is_object($package)) {
$output->write($indent . str_pad($package->getPrettyName(), $nameLength, ' '), false); $output->write($indent . str_pad($package->getPrettyName(), $nameLength, ' '), false);
@ -241,18 +247,17 @@ EOT
} }
$output->write(' ' . $description); $output->write(' ' . $description);
} }
} else {
$output->write($indent . $package);
}
if ($writePath) { if ($writePath) {
$path = strtok(realpath($composer->getInstallationManager()->getInstallPath($package)), "\r\n"); $path = strtok(realpath($composer->getInstallationManager()->getInstallPath($package)), "\r\n");
$output->write(' ' . $path); $output->write(' ' . $path);
} }
} else {
$output->write($indent . $package);
} }
$io->write(''); $io->write('');
} }
if ($tree) { if ($showAllTypes) {
$io->write(''); $io->write('');
} }
} }
@ -447,9 +452,9 @@ EOT
$this->colors = array( $this->colors = array(
'green', 'green',
'yellow', 'yellow',
'blue',
'magenta',
'cyan', 'cyan',
'magenta',
'blue',
); );
foreach ($this->colors as $color) { foreach ($this->colors as $color) {
@ -466,18 +471,14 @@ EOT
* @param RepositoryInterface $distantRepos * @param RepositoryInterface $distantRepos
* @param OutputInterface $output * @param OutputInterface $output
*/ */
protected function displayPackageTree($package, RepositoryInterface $installedRepo, RepositoryInterface $distantRepos, OutputInterface $output) protected function displayPackageTree(PackageInterface $package, RepositoryInterface $installedRepo, RepositoryInterface $distantRepos, OutputInterface $output)
{ {
$packagesInTree = array(); $packagesInTree = array();
$packagesInTree[] = $package; $packagesInTree[] = $package;
if (is_object($package)) {
$output->write(sprintf('<info>%s</info>', $package->getPrettyName())); $output->write(sprintf('<info>%s</info>', $package->getPrettyName()));
$output->write(' ' . $package->getPrettyVersion()); $output->write(' ' . $package->getPrettyVersion());
$output->write(' ' . strtok($package->getDescription(), "\r\n")); $output->write(' ' . strtok($package->getDescription(), "\r\n"));
} else {
$output->write(sprintf('<info>%s</info>', $package));
}
$output->writeln(''); $output->writeln('');
if (is_object($package)) { if (is_object($package)) {
@ -522,7 +523,7 @@ EOT
protected function displayTree($name, $package, RepositoryInterface $installedRepo, RepositoryInterface $distantRepos, array $packagesInTree, OutputInterface $output, $previousTreeBar = '├', $level = 1) protected function displayTree($name, $package, RepositoryInterface $installedRepo, RepositoryInterface $distantRepos, array $packagesInTree, OutputInterface $output, $previousTreeBar = '├', $level = 1)
{ {
$previousTreeBar = str_replace('├', '│', $previousTreeBar); $previousTreeBar = str_replace('├', '│', $previousTreeBar);
list($package, $versions) = $this->getPackage($installedRepo, $distantRepos, $name, $package->getPrettyConstraint() == 'self.version' ? $package->getConstraint() : $package->getPrettyConstraint()); list($package, $versions) = $this->getPackage($installedRepo, $distantRepos, $name, $package->getPrettyConstraint() === 'self.version' ? $package->getConstraint() : $package->getPrettyConstraint());
if (is_object($package)) { if (is_object($package)) {
$requires = $package->getRequires(); $requires = $package->getRequires();
$treeBar = $previousTreeBar . ' ├'; $treeBar = $previousTreeBar . ' ├';