Browse Source

added description to show command, searching in description aswell

digitalkaoz 13 năm trước cách đây
mục cha
commit
741a66e504

+ 18 - 2
src/Composer/Command/SearchCommand.php

@@ -18,6 +18,7 @@ use Symfony\Component\Console\Output\OutputInterface;
 use Composer\Repository\CompositeRepository;
 use Composer\Repository\PlatformRepository;
 use Composer\Repository\ComposerRepository;
+use Composer\Package\PackageInterface;
 
 /**
  * @author Robert Schönthal <seroscho@googlemail.com>
@@ -60,8 +61,8 @@ EOT
 
         foreach ($repos->getPackages() as $package) {
             foreach ($tokens as $token) {
-                if (false === ($pos = strpos($package->getName(), $token)) && (false === strpos(join(',',$package->getKeywords() ?: array()), $token))) {
-                    continue;
+                if ($this->isUnmatchedPackage($package, $token)) {
+                   continue;
                 }
 
                 if (false !== ($pos = strpos($package->getName(), $token))) {
@@ -83,4 +84,19 @@ EOT
             $output->writeln($name .' <comment>:</comment> '. join(', ', $versions));
         }
     }
+
+    /**
+     * tries to find a token within the name/keywords/description
+     *
+     * @param PackageInterface $package
+     * @param string $token
+     * @return boolean
+     */
+    private function isUnmatchedPackage(PackageInterface $package, $token)
+    {
+        return (false === strpos($package->getName(), $token)) &&
+            (false === strpos(join(',',$package->getKeywords() ?: array()), $token)) &&
+            (false === strpos($package->getDescription(), $token))
+        ;
+    }
 }

+ 1 - 1
src/Composer/Command/ShowCommand.php

@@ -132,7 +132,7 @@ EOT
      */
     protected function printMeta(InputInterface $input, OutputInterface $output, PackageInterface $package, RepositoryInterface $installedRepo, RepositoryInterface $repos)
     {
-        $output->writeln('<info>name</info>     : ' . $package->getPrettyName());
+        $output->writeln('<info>name</info>     : <comment>' . $package->getPrettyName(). '</comment> '.$package->getDescription());
         $this->printVersions($input, $output, $package, $installedRepo, $repos);
         $output->writeln('<info>type</info>     : ' . $package->getType());
         $output->writeln('<info>names</info>    : ' . join(', ', $package->getNames()));