From 42c501aaa44d4a46367ba78236fcb4a6218ba483 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Sat, 26 May 2012 15:17:52 +0200 Subject: [PATCH] Force the installation of the newly required packages in require command --- src/Composer/Command/RequireCommand.php | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/Composer/Command/RequireCommand.php b/src/Composer/Command/RequireCommand.php index 26840e7f3..92d21fef2 100644 --- a/src/Composer/Command/RequireCommand.php +++ b/src/Composer/Command/RequireCommand.php @@ -17,6 +17,7 @@ use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use Composer\Factory; +use Composer\Installer; use Composer\Json\JsonFile; use Composer\Json\JsonManipulator; use Composer\Json\JsonValidationException; @@ -32,13 +33,14 @@ class RequireCommand extends InitCommand { $this ->setName('require') - ->setDescription('Adds a required package to a composer.json') + ->setDescription('Adds required packages to your composer.json and installs them') ->setDefinition(array( new InputArgument('packages', InputArgument::IS_ARRAY | InputArgument::OPTIONAL, 'Required package with a version constraint, e.g. foo/bar:1.0.0 or foo/bar=1.0.0 or "foo/bar 1.0.0"'), new InputOption('dev', null, InputOption::VALUE_NONE, 'Add requirement to require-dev.'), + new InputOption('prefer-source', null, InputOption::VALUE_NONE, 'Forces installation from package sources when possible, including VCS information.'), )) ->setHelp(<<writeln(''.$file.' has been updated'); + + // Update packages + $composer = $this->getComposer(); + $io = $this->getIO(); + $install = Installer::create($io, $composer); + + $install + ->setVerbose($input->getOption('verbose')) + ->setPreferSource($input->getOption('prefer-source')) + ->setDevMode($input->getOption('dev')) + ->setUpdate(true) + ->setUpdateWhitelist($requirements); + ; + + return $install->run() ? 0 : 1; } private function updateFileCleanly($json, array $base, array $new, $requireKey)