From 6b6d6b6d82d63c690bd883d53b4acc98769af84a Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Sun, 30 Oct 2011 20:59:41 +0100 Subject: [PATCH] Add --dev flag to InstallCommand to do source installs, fixes #26 --- bin/composer | 2 +- src/Composer/Command/InstallCommand.php | 8 ++++++++ src/Composer/Downloader/DownloadManager.php | 2 +- tests/Composer/Test/Downloader/DownloadManagerTest.php | 8 ++++---- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/bin/composer b/bin/composer index 72eda90a4..dada7b2eb 100755 --- a/bin/composer +++ b/bin/composer @@ -21,7 +21,7 @@ $rm->setRepositoryClass('pear', 'Composer\Repository\PearRepository'); $rm->setRepositoryClass('package', 'Composer\Repository\PackageRepository'); // initialize download manager -$dm = new Downloader\DownloadManager($preferSource = false); +$dm = new Downloader\DownloadManager(); $dm->setDownloader('git', new Downloader\GitDownloader()); $dm->setDownloader('pear', new Downloader\PearDownloader()); $dm->setDownloader('zip', new Downloader\ZipDownloader()); diff --git a/src/Composer/Command/InstallCommand.php b/src/Composer/Command/InstallCommand.php index 1f55bc671..e96b29141 100644 --- a/src/Composer/Command/InstallCommand.php +++ b/src/Composer/Command/InstallCommand.php @@ -20,6 +20,7 @@ use Composer\DependencyResolver\Operation; use Composer\Package\LinkConstraint\VersionConstraint; use Composer\Repository\PlatformRepository; use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; /** @@ -34,6 +35,9 @@ class InstallCommand extends Command $this ->setName('install') ->setDescription('Parses the composer.json file and downloads the needed dependencies.') + ->setDefinition(array( + new InputOption('dev', null, InputOption::VALUE_NONE, 'Forces installation from package sources when possible, including VCS information.'), + )) ->setHelp(<<install command reads the composer.json file from the current directory, processes it, and downloads and installs all the @@ -50,6 +54,10 @@ EOT { $composer = $this->getComposer(); + if ($input->getOption('dev')) { + $composer->getDownloadManager()->setPreferSource(true); + } + // create local repo, this contains all packages that are installed in the local project $localRepo = $composer->getRepositoryManager()->getLocalRepository(); // create installed repo, this contains all local packages + platform packages (php & extensions) diff --git a/src/Composer/Downloader/DownloadManager.php b/src/Composer/Downloader/DownloadManager.php index 5078a7f9a..dcbd28507 100644 --- a/src/Composer/Downloader/DownloadManager.php +++ b/src/Composer/Downloader/DownloadManager.php @@ -40,7 +40,7 @@ class DownloadManager * * @param Boolean $preferSource prefer downloading from source */ - public function preferSource($preferSource = true) + public function setPreferSource($preferSource) { $this->preferSource = $preferSource; } diff --git a/tests/Composer/Test/Downloader/DownloadManagerTest.php b/tests/Composer/Test/Downloader/DownloadManagerTest.php index fd55f77e6..9c1e2894c 100644 --- a/tests/Composer/Test/Downloader/DownloadManagerTest.php +++ b/tests/Composer/Test/Downloader/DownloadManagerTest.php @@ -326,7 +326,7 @@ class DownloadManagerTest extends \PHPUnit_Framework_TestCase ->with($package) ->will($this->returnValue($downloader)); - $manager->preferSource(); + $manager->setPreferSource(true); $manager->download($package, 'target_dir'); } @@ -362,7 +362,7 @@ class DownloadManagerTest extends \PHPUnit_Framework_TestCase ->with($package) ->will($this->returnValue($downloader)); - $manager->preferSource(); + $manager->setPreferSource(true); $manager->download($package, 'target_dir'); } @@ -398,7 +398,7 @@ class DownloadManagerTest extends \PHPUnit_Framework_TestCase ->with($package) ->will($this->returnValue($downloader)); - $manager->preferSource(); + $manager->setPreferSource(true); $manager->download($package, 'target_dir'); } @@ -415,7 +415,7 @@ class DownloadManagerTest extends \PHPUnit_Framework_TestCase ->will($this->returnValue(null)); $manager = new DownloadManager(); - $manager->preferSource(); + $manager->setPreferSource(true); $this->setExpectedException('InvalidArgumentException'); $manager->download($package, 'target_dir');