Selaa lähdekoodia

Merge remote-tracking branch 'digitalkaoz/command_refactorings'

Jordi Boggiano 13 vuotta sitten
vanhempi
commit
8273579461

+ 32 - 5
src/Composer/Command/DebugPackagesCommand.php

@@ -20,6 +20,7 @@ use Composer\DependencyResolver\Operation;
 use Composer\Package\LinkConstraint\VersionConstraint;
 use Composer\Repository\PlatformRepository;
 use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Input\InputOption;
 use Symfony\Component\Console\Output\OutputInterface;
 
 /**
@@ -32,6 +33,10 @@ class DebugPackagesCommand extends Command
         $this
             ->setName('debug:packages')
             ->setDescription('Lists all existing packages and their version')
+            ->setDefinition(array(
+                new InputOption('local', null, InputOption::VALUE_NONE, 'list locally installed packages only'),
+                new InputOption('platform', null, InputOption::VALUE_NONE, 'list platform packages only'),
+            ))
             ->setHelp(<<<EOT
 <info>php composer.phar debug:packages</info>
 
@@ -45,18 +50,40 @@ EOT
         $composer = $this->getComposer();
 
         // create local repo, this contains all packages that are installed in the local project
-        $localRepo           = $composer->getRepositoryManager()->getLocalRepository();
+        $localRepo = $composer->getRepositoryManager()->getLocalRepository();
         // create installed repo, this contains all local packages + platform packages (php & extensions)
-        $installedRepo       = new PlatformRepository($localRepo);
+        $installedRepo = new PlatformRepository($localRepo);
+
+        if ($input->getOption('local')) {
+            foreach ($localRepo->getPackages() as $package) {
+                $output->writeln('<info>local:</info> ' . $package->getPrettyName() . ' ' . $package->getPrettyVersion() . '<comment> (' . $package->getVersion() . ')</comment>');
+            }
+
+            return;
+        }
+
+        if ($input->getOption('platform')) {
+            $repos = array_diff($installedRepo->getPackages(), $localRepo->getPackages());
+            foreach ($repos as $package) {
+                $output->writeln('<info>plattform:</info> ' . $package->getPrettyName() . ' ' . $package->getPrettyVersion() . '<comment> (' . $package->getVersion() . ')</comment>');
+            }
+
+            return;
+        }
 
         foreach ($installedRepo->getPackages() as $package) {
-            $output->writeln('installed: '.$package->getPrettyName().' '.$package->getPrettyVersion().' ('.$package->getName().' '.$package->getVersion().')');
+            if ($localRepo->hasPackage($package)) {
+                $output->writeln('<info>installed:</info> ' . $package->getPrettyName() . ' ' . $package->getPrettyVersion() . '<comment> (' . $package->getVersion() . ')</comment>');
+            } else {
+                $output->writeln('<info>platform:</info> ' . $package->getPrettyName() . ' ' . $package->getPrettyVersion() . '<comment> (' . $package->getName() . ' ' . $package->getVersion() . ')</comment>');
+            }
         }
 
         foreach ($composer->getRepositoryManager()->getRepositories() as $repository) {
             foreach ($repository->getPackages() as $package) {
-                $output->writeln('available: '.$package->getPrettyName().' '.$package->getPrettyVersion().' ('.$package->getName().' '.$package->getVersion().')');
+                $output->writeln('<comment>available:</comment> ' . $package->getPrettyName() . ' ' . $package->getPrettyVersion() . '<comment> (' . $package->getName() . ' ' . $package->getVersion() . ')</comment>');
             }
         }
     }
-}
+
+}

+ 6 - 6
src/Composer/Command/InstallCommand.php

@@ -85,7 +85,7 @@ EOT
         // creating requirements request
         $request = new Request($pool);
         if ($update) {
-            $output->writeln('> Updating dependencies.');
+            $output->writeln('<info>Updating dependencies.</info>');
             $listedPackages = array();
             $installedPackages = $installedRepo->getPackages();
             $links = $this->collectLinks($input, $composer->getPackage());
@@ -108,14 +108,14 @@ EOT
                 $request->install($link->getTarget(), $link->getConstraint());
             }
         } elseif ($composer->getLocker()->isLocked()) {
-            $output->writeln('> Found lockfile. Reading.');
+            $output->writeln('<info>Found lockfile. Reading.</info>');
 
             foreach ($composer->getLocker()->getLockedPackages() as $package) {
                 $constraint = new VersionConstraint('=', $package->getVersion());
                 $request->install($package->getName(), $constraint);
             }
         } else {
-            $output->writeln('> Installing dependencies.');
+            $output->writeln('<info>Installing dependencies.</info>');
 
             $links = $this->collectLinks($input, $composer->getPackage());
 
@@ -170,17 +170,17 @@ EOT
         if (!$dryRun) {
             if ($update || !$composer->getLocker()->isLocked()) {
                 $composer->getLocker()->lockPackages($localRepo->getPackages());
-                $output->writeln('> Locked');
+                $output->writeln('<info>Locked</info>');
             }
 
             $localRepo->write();
 
-            $output->writeln('> Generating autoload files');
+            $output->writeln('<info>Generating autoload files</info>');
             $generator = new AutoloadGenerator;
             $generator->dump($localRepo, $composer->getPackage(), $installationManager, $installationManager->getVendorPath().'/.composer');
         }
 
-        $output->writeln('> Done');
+        $output->writeln('<info>Done</info>');
     }
 
     private function collectLinks(InputInterface $input, PackageInterface $package)

+ 63 - 0
src/Composer/Command/SearchCommand.php

@@ -0,0 +1,63 @@
+<?php
+
+/*
+ * This file is part of Composer.
+ *
+ * (c) Nils Adermann <naderman@naderman.de>
+ *     Jordi Boggiano <j.boggiano@seld.be>
+ *
+ * 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;
+
+/**
+ * @author Robert Schönthal <seroscho@googlemail.com>
+ */
+class SearchCommand extends Command
+{
+    protected function configure()
+    {
+        $this
+            ->setName('search')
+            ->setDescription('search for packages')
+            ->setDefinition(array(
+                new InputArgument('tokens', InputArgument::IS_ARRAY, 'tokens to search for'),
+            ))
+            ->setHelp(<<<EOT
+The search command searches for packages by its name
+<info>php composer.phar search symfony composer</info>
+
+EOT
+            )
+        ;
+    }
+
+    protected function execute(InputInterface $input, OutputInterface $output)
+    {
+        $composer = $this->getComposer();
+
+        // create local repo, this contains all packages that are installed in the local project
+        $localRepo = $composer->getRepositoryManager()->getLocalRepository();
+
+        foreach ($composer->getRepositoryManager()->getRepositories() as $repository) {
+            foreach ($repository->getPackages() as $package) {
+                foreach ((array) $input->getArgument('tokens') as $token) {
+                    if (false === strpos($package->getName(), $token)) {
+                        continue;
+                    }
+
+                    $state = $localRepo->hasPackage($package) ? '<info>installed</info>' : $state = '<comment>available</comment>';
+
+                    $output->writeln($state . ': ' . $package->getPrettyName() . ' <comment>' . $package->getPrettyVersion() . '</comment>');
+                }
+            }
+        }
+    }
+}

+ 2 - 2
src/Composer/Command/SelfUpdateCommand.php

@@ -42,14 +42,14 @@ EOT
         $latest = trim(file_get_contents('http://getcomposer.org/version'));
 
         if (Composer::VERSION !== $latest) {
-            $output->writeln(sprintf("Updating to version %s.", $latest));
+            $output->writeln(sprintf("Updating to version <info>%s</info>.", $latest));
 
             $remoteFilename = 'http://getcomposer.org/composer.phar';
             $localFilename = $_SERVER['argv'][0];
 
             file_put_contents($localFilename, file_get_contents($remoteFilename));
         } else {
-            $output->writeln("You are using the latest composer version.");
+            $output->writeln("<info>You are using the latest composer version.</info>");
         }
     }
 }

+ 1 - 0
src/Composer/Console/Application.php

@@ -162,6 +162,7 @@ class Application extends BaseApplication
         $this->add(new Command\InstallCommand());
         $this->add(new Command\UpdateCommand());
         $this->add(new Command\DebugPackagesCommand());
+        $this->add(new Command\SearchCommand());
 
         if ('phar:' === substr(__FILE__, 0, 5)) {
             $this->add(new Command\SelfUpdateCommand());