1
0
Fork 0

Force the installation of the newly required packages in require command

pull/736/head
Jordi Boggiano 2012-05-26 15:17:52 +02:00
parent 1443ea25f9
commit 42c501aaa4
1 changed files with 19 additions and 2 deletions

View File

@ -17,6 +17,7 @@ use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
use Composer\Factory; use Composer\Factory;
use Composer\Installer;
use Composer\Json\JsonFile; use Composer\Json\JsonFile;
use Composer\Json\JsonManipulator; use Composer\Json\JsonManipulator;
use Composer\Json\JsonValidationException; use Composer\Json\JsonValidationException;
@ -32,13 +33,14 @@ class RequireCommand extends InitCommand
{ {
$this $this
->setName('require') ->setName('require')
->setDescription('Adds a required package to a composer.json') ->setDescription('Adds required packages to your composer.json and installs them')
->setDefinition(array( ->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 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('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(<<<EOT ->setHelp(<<<EOT
The require command adds requirements to your composer.json The require command adds required packages to your composer.json and installs them
EOT EOT
) )
@ -80,6 +82,21 @@ EOT
} }
$output->writeln('<info>'.$file.' has been updated</info>'); $output->writeln('<info>'.$file.' has been updated</info>');
// 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) private function updateFileCleanly($json, array $base, array $new, $requireKey)