Browse Source

Install recommended deps by default and introduce flags for including/excluding required/recommended/suggested deps

jsor 13 years ago
parent
commit
9af21fd461
2 changed files with 29 additions and 2 deletions
  1. 27 2
      src/Composer/Command/InstallCommand.php
  2. 2 0
      src/Composer/Command/UpdateCommand.php

+ 27 - 2
src/Composer/Command/InstallCommand.php

@@ -18,6 +18,7 @@ use Composer\DependencyResolver\Pool;
 use Composer\DependencyResolver\Request;
 use Composer\DependencyResolver\Request;
 use Composer\DependencyResolver\Operation;
 use Composer\DependencyResolver\Operation;
 use Composer\Package\LinkConstraint\VersionConstraint;
 use Composer\Package\LinkConstraint\VersionConstraint;
+use Composer\Package\PackageInterface;
 use Composer\Repository\PlatformRepository;
 use Composer\Repository\PlatformRepository;
 use Symfony\Component\Console\Input\InputInterface;
 use Symfony\Component\Console\Input\InputInterface;
 use Symfony\Component\Console\Input\InputOption;
 use Symfony\Component\Console\Input\InputOption;
@@ -38,6 +39,8 @@ class InstallCommand extends Command
             ->setDefinition(array(
             ->setDefinition(array(
                 new InputOption('dev', null, InputOption::VALUE_NONE, 'Forces installation from package sources when possible, including VCS information.'),
                 new InputOption('dev', null, InputOption::VALUE_NONE, 'Forces installation from package sources when possible, including VCS information.'),
                 new InputOption('dry-run', null, InputOption::VALUE_NONE, 'Outputs the operations but will not execute anything (implicitly enables --verbose).'),
                 new InputOption('dry-run', null, InputOption::VALUE_NONE, 'Outputs the operations but will not execute anything (implicitly enables --verbose).'),
+                new InputOption('required-only', null, InputOption::VALUE_NONE, 'Installs required packages only (ignored when installing from an existing lock file).'),
+                new InputOption('include-suggested', null, InputOption::VALUE_NONE, 'Includes suggested packages (ignored when installing from an existing lock file).'),
             ))
             ))
             ->setHelp(<<<EOT
             ->setHelp(<<<EOT
 The <info>install</info> command reads the composer.json file from the
 The <info>install</info> command reads the composer.json file from the
@@ -85,8 +88,9 @@ EOT
             $output->writeln('> Updating dependencies.');
             $output->writeln('> Updating dependencies.');
             $listedPackages = array();
             $listedPackages = array();
             $installedPackages = $installedRepo->getPackages();
             $installedPackages = $installedRepo->getPackages();
+            $links = $this->collectLinks($input, $composer->getPackage());
 
 
-            foreach ($composer->getPackage()->getRequires() as $link) {
+            foreach ($links as $link) {
                 $listedPackages[] = $link->getTarget();
                 $listedPackages[] = $link->getTarget();
 
 
                 foreach ($installedPackages as $package) {
                 foreach ($installedPackages as $package) {
@@ -112,7 +116,10 @@ EOT
             }
             }
         } else {
         } else {
             $output->writeln('> Installing dependencies.');
             $output->writeln('> Installing dependencies.');
-            foreach ($composer->getPackage()->getRequires() as $link) {
+
+            $links = $this->collectLinks($input, $composer->getPackage());
+
+            foreach ($links as $link) {
                 $request->install($link->getTarget(), $link->getConstraint());
                 $request->install($link->getTarget(), $link->getConstraint());
             }
             }
         }
         }
@@ -175,4 +182,22 @@ EOT
 
 
         $output->writeln('> Done');
         $output->writeln('> Done');
     }
     }
+
+    private function collectLinks(InputInterface $input, PackageInterface $package)
+    {
+        $requiredOnly     = (Boolean) $input->getOption('required-only');
+        $includeSuggested = (Boolean) $input->getOption('include-suggested');
+
+        $links = $package->getRequires();
+
+        if (!$requiredOnly) {
+            $links = array_merge($links, $package->getRecommends());
+
+            if ($includeSuggested) {
+                $links = array_merge($links, $package->getSuggests());
+            }
+        }
+
+        return $links;
+    }
 }
 }

+ 2 - 0
src/Composer/Command/UpdateCommand.php

@@ -36,6 +36,8 @@ class UpdateCommand extends Command
             ->setDefinition(array(
             ->setDefinition(array(
                 new InputOption('dev', null, InputOption::VALUE_NONE, 'Forces installation from package sources when possible, including VCS information.'),
                 new InputOption('dev', null, InputOption::VALUE_NONE, 'Forces installation from package sources when possible, including VCS information.'),
                 new InputOption('dry-run', null, InputOption::VALUE_NONE, 'Outputs the operations but will not execute anything (implicitly enables --verbose).'),
                 new InputOption('dry-run', null, InputOption::VALUE_NONE, 'Outputs the operations but will not execute anything (implicitly enables --verbose).'),
+                new InputOption('required-only', null, InputOption::VALUE_NONE, 'Installs required packages only.'),
+                new InputOption('include-suggested', null, InputOption::VALUE_NONE, 'Includes suggested packages.'),
             ))
             ))
             ->setHelp(<<<EOT
             ->setHelp(<<<EOT
 The <info>update</info> command reads the composer.json file from the
 The <info>update</info> command reads the composer.json file from the