diff --git a/.gitignore b/.gitignore index d5221c1d5..1f3f354dd 100644 --- a/.gitignore +++ b/.gitignore @@ -3,5 +3,4 @@ /.buildpath /composer.phar /composer.lock -/vendor -/nbproject/private/ \ No newline at end of file +/vendor \ No newline at end of file diff --git a/src/Composer/Command/ShowCommand.php b/src/Composer/Command/ShowCommand.php new file mode 100644 index 000000000..12ad48827 --- /dev/null +++ b/src/Composer/Command/ShowCommand.php @@ -0,0 +1,163 @@ + + * Jordi Boggiano + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Composer\Command; + +use Composer\Repository\PlatformRepository; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Output\OutputInterface; +use Composer\Package\Dumper\ArrayDumper; + +/** + * @author Robert Schönthal + */ +class ShowCommand extends Command +{ + + //holds the array dump of an package + private $dump; + private $output; + + protected function configure() + { + $this + ->setName('show') + ->setDescription('show package details') + ->setDefinition(array( + new InputArgument('package', InputArgument::REQUIRED, 'the package to inspect'), + new InputArgument('version', InputArgument::OPTIONAL, 'the version'), + )) + ->setHelp(<<php composer.phar show composer/composer master-dev + +EOT + ) + ; + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $dumper = new ArrayDumper(); + $this->output = $output; + $this->dump = $dumper->dump($this->getPackage($input)); + + $this->printMeta($input); + $this->printLinks('requires'); + $this->printLinks('recommends'); + $this->printLinks('replaces'); + } + + /** + * finds a package by name and version if provided + * + * @param InputInterface $input + * @return PackageInterface + * @throws \InvalidArgumentException + */ + protected function getPackage(InputInterface $input) + { + $composer = $this->getComposer(); + $localRepo = $composer->getRepositoryManager()->getLocalRepository(); + + //we have a name and a version so we can use ::findPackage + if ($input->getArgument('version')) { + return $composer->getRepositoryManager()->findPackage($input->getArgument('package'), $input->getArgument('version')); + } + + //check if we have a local installation so we can grab the right package/version + foreach ($localRepo->getPackages() as $package) { + if ($package->getName() === $input->getArgument('package')) { + return $package; + } + } + + //we only have a name, so search for the first package where the name matches + foreach ($composer->getRepositoryManager()->getRepositories() as $repository) { + foreach ($repository->getPackages() as $package) { + if ($package->getName() == $input->getArgument('package')) { + return $package; + } + } + } + + throw new \InvalidArgumentException('no package found'); + } + + /** + * prints package meta data + */ + protected function printMeta(InputInterface $input) + { + $this->output->writeln('name : ' . $this->dump['name']); + $this->printVersions($input); + $this->output->writeln('type : ' . $this->dump['type']); + $this->output->writeln('names : ' . join(', ', $this->dump['names'])); + $this->output->writeln('source : ' . sprintf('[%s] %s %s', $this->dump['source']['type'], $this->dump['source']['url'], $this->dump['source']['reference'])); + $this->output->writeln('dist : ' . sprintf('[%s] %s %s', $this->dump['dist']['type'], $this->dump['dist']['url'], $this->dump['dist']['reference'])); + $this->output->writeln('licence : ' . join(', ', $this->dump['license'])); + $this->output->writeln("\nautoload"); + + if (array_key_exists('autoload', $this->dump)) { + foreach ($this->dump['autoload'] as $type => $autoloads) { + $this->output->writeln('' . $type . ''); + + foreach ($autoloads as $name => $path) { + $this->output->writeln($name .' : '. $path); + } + } + } + } + + /** + * prints all available versions of this package and highlights the installed one if any + */ + protected function printVersions(InputInterface $input) + { + if ($input->getArgument('version')) { + $this->output->writeln('version : ' . $this->dump['version_normalized']); + return; + } + + $versions = array(); + + foreach ($this->getComposer()->getRepositoryManager()->getRepositories() as $repository) { + foreach ($repository->getPackages() as $package) { + if ($package->getName() === $this->dump['name']) { + $versions[] = $package->getPrettyVersion(); + } + } + } + + $versions = str_replace($this->dump['version'], '' . $this->dump['version'] . '', join(', ', $versions)); + + $this->output->writeln('versions : ' . $versions); + } + + /** + * print link objects + * + * @param string $linksName + */ + protected function printLinks($linksName) + { + if (isset($this->dump[$linksName])) { + + $this->output->writeln("\n" . $linksName . ""); + + foreach ($this->dump[$linksName] as $link) { + $this->output->writeln($link->getTarget() . ' ' . $link->getPrettyConstraint() . ''); + } + } + } +} \ No newline at end of file diff --git a/src/Composer/Console/Application.php b/src/Composer/Console/Application.php index c0871bf4b..65cbacad3 100644 --- a/src/Composer/Console/Application.php +++ b/src/Composer/Console/Application.php @@ -175,6 +175,7 @@ class Application extends BaseApplication $this->add(new Command\UpdateCommand()); $this->add(new Command\DebugPackagesCommand()); $this->add(new Command\SearchCommand()); + $this->add(new Command\ShowCommand()); if ('phar:' === substr(__FILE__, 0, 5)) { $this->add(new Command\SelfUpdateCommand());