From 9af21fd461a90422fda865dde73d404ba63086ab Mon Sep 17 00:00:00 2001 From: jsor Date: Fri, 25 Nov 2011 16:44:50 +0100 Subject: [PATCH 1/3] Install recommended deps by default and introduce flags for including/excluding required/recommended/suggested deps --- src/Composer/Command/InstallCommand.php | 29 +++++++++++++++++++++++-- src/Composer/Command/UpdateCommand.php | 2 ++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/Composer/Command/InstallCommand.php b/src/Composer/Command/InstallCommand.php index 52f36da34..dc1c7d7b7 100644 --- a/src/Composer/Command/InstallCommand.php +++ b/src/Composer/Command/InstallCommand.php @@ -18,6 +18,7 @@ use Composer\DependencyResolver\Pool; use Composer\DependencyResolver\Request; use Composer\DependencyResolver\Operation; use Composer\Package\LinkConstraint\VersionConstraint; +use Composer\Package\PackageInterface; use Composer\Repository\PlatformRepository; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; @@ -38,6 +39,8 @@ class InstallCommand extends Command ->setDefinition(array( 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('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(<<install command reads the composer.json file from the @@ -85,8 +88,9 @@ EOT $output->writeln('> Updating dependencies.'); $listedPackages = array(); $installedPackages = $installedRepo->getPackages(); + $links = $this->collectLinks($input, $composer->getPackage()); - foreach ($composer->getPackage()->getRequires() as $link) { + foreach ($links as $link) { $listedPackages[] = $link->getTarget(); foreach ($installedPackages as $package) { @@ -112,7 +116,10 @@ EOT } } else { $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()); } } @@ -175,4 +182,22 @@ EOT $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; + } } diff --git a/src/Composer/Command/UpdateCommand.php b/src/Composer/Command/UpdateCommand.php index 4af6fbb4d..34a3a63ff 100644 --- a/src/Composer/Command/UpdateCommand.php +++ b/src/Composer/Command/UpdateCommand.php @@ -36,6 +36,8 @@ class UpdateCommand extends Command ->setDefinition(array( 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('required-only', null, InputOption::VALUE_NONE, 'Installs required packages only.'), + new InputOption('include-suggested', null, InputOption::VALUE_NONE, 'Includes suggested packages.'), )) ->setHelp(<<update command reads the composer.json file from the From e512e16e354321a9239f07ccc31246d54a1e98ae Mon Sep 17 00:00:00 2001 From: jsor Date: Fri, 25 Nov 2011 18:01:12 +0100 Subject: [PATCH 2/3] Rename flags after feedback in #132 --- src/Composer/Command/InstallCommand.php | 8 ++++---- src/Composer/Command/UpdateCommand.php | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Composer/Command/InstallCommand.php b/src/Composer/Command/InstallCommand.php index dc1c7d7b7..f11510e0e 100644 --- a/src/Composer/Command/InstallCommand.php +++ b/src/Composer/Command/InstallCommand.php @@ -39,8 +39,8 @@ class InstallCommand extends Command ->setDefinition(array( 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('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).'), + new InputOption('no-install-recommends', null, InputOption::VALUE_NONE, 'Do not install recommended packages (ignored when installing from an existing lock file).'), + new InputOption('install-suggests', null, InputOption::VALUE_NONE, 'Also install suggested packages (ignored when installing from an existing lock file).'), )) ->setHelp(<<install command reads the composer.json file from the @@ -185,8 +185,8 @@ EOT private function collectLinks(InputInterface $input, PackageInterface $package) { - $requiredOnly = (Boolean) $input->getOption('required-only'); - $includeSuggested = (Boolean) $input->getOption('include-suggested'); + $requiredOnly = (Boolean) $input->getOption('no-install-recommends'); + $includeSuggested = (Boolean) $input->getOption('install-suggests'); $links = $package->getRequires(); diff --git a/src/Composer/Command/UpdateCommand.php b/src/Composer/Command/UpdateCommand.php index 34a3a63ff..4384b955f 100644 --- a/src/Composer/Command/UpdateCommand.php +++ b/src/Composer/Command/UpdateCommand.php @@ -36,8 +36,8 @@ class UpdateCommand extends Command ->setDefinition(array( 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('required-only', null, InputOption::VALUE_NONE, 'Installs required packages only.'), - new InputOption('include-suggested', null, InputOption::VALUE_NONE, 'Includes suggested packages.'), + new InputOption('no-install-recommends', null, InputOption::VALUE_NONE, 'Do not install recommended packages.'), + new InputOption('install-suggests', null, InputOption::VALUE_NONE, 'Also install suggested packages.'), )) ->setHelp(<<update command reads the composer.json file from the From 28a8b3e4c501a2c74b9b5e90ab94c2bde717b879 Mon Sep 17 00:00:00 2001 From: jsor Date: Mon, 28 Nov 2011 08:51:00 +0100 Subject: [PATCH 3/3] Fix link collection --- src/Composer/Command/InstallCommand.php | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/Composer/Command/InstallCommand.php b/src/Composer/Command/InstallCommand.php index f11510e0e..a10d16901 100644 --- a/src/Composer/Command/InstallCommand.php +++ b/src/Composer/Command/InstallCommand.php @@ -185,17 +185,14 @@ EOT private function collectLinks(InputInterface $input, PackageInterface $package) { - $requiredOnly = (Boolean) $input->getOption('no-install-recommends'); - $includeSuggested = (Boolean) $input->getOption('install-suggests'); - $links = $package->getRequires(); - if (!$requiredOnly) { + if (!$input->getOption('no-install-recommends')) { $links = array_merge($links, $package->getRecommends()); + } - if ($includeSuggested) { - $links = array_merge($links, $package->getSuggests()); - } + if ($input->getOption('install-suggests')) { + $links = array_merge($links, $package->getSuggests()); } return $links;