diff --git a/doc/03-cli.md b/doc/03-cli.md index c985578f8..95c6997fa 100644 --- a/doc/03-cli.md +++ b/doc/03-cli.md @@ -342,6 +342,8 @@ symfony/symfony * **--link-type:** The link types to match on, can be specified multiple times. +* **--with-replaces:** Search for replaced packages too. Works great +for packages like [`symfony/symfony`](https://packagist.org/packages/symfony/symfony). ## validate diff --git a/src/Composer/Command/DependsCommand.php b/src/Composer/Command/DependsCommand.php index 765164f14..dad557880 100644 --- a/src/Composer/Command/DependsCommand.php +++ b/src/Composer/Command/DependsCommand.php @@ -43,6 +43,7 @@ class DependsCommand extends Command ->setDefinition(array( new InputArgument('package', InputArgument::REQUIRED, 'Package to inspect'), new InputOption('link-type', '', InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Link types to show (require, require-dev)', array_keys($this->linkTypes)), + new InputOption('with-replaces', '', InputOption::VALUE_NONE, 'Search for replaced packages too'), )) ->setHelp(<<getOption('link-type')); + $needles = array($needle); + if (true === $input->getOption('with-replaces')) { + foreach ($packages as $package) { + $needles = array_merge($needles, array_map(function (Link $link) { + return $link->getTarget(); + }, $package->getReplaces())); + } + } + $messages = array(); $outputPackages = array(); $io = $this->getIO(); @@ -94,10 +104,12 @@ EOT foreach ($types as $type) { /** @var Link $link */ foreach ($package->{'get'.$linkTypes[$type][0]}() as $link) { - if ($link->getTarget() === $needle) { - if (!isset($outputPackages[$package->getName()])) { - $messages[] = ''.$package->getPrettyName() . ' ' . $linkTypes[$type][1] . ' ' . $needle .' (' . $link->getPrettyConstraint() . ')'; - $outputPackages[$package->getName()] = true; + foreach ($needles as $needle) { + if ($link->getTarget() === $needle) { + if (!isset($outputPackages[$package->getName()][$needle])) { + $messages[] = ''.$package->getPrettyName() . ' ' . $linkTypes[$type][1] . ' ' . $needle .' (' . $link->getPrettyConstraint() . ')'; + $outputPackages[$package->getName()][$needle] = true; + } } } }