Browse Source

Add --dev flag to InstallCommand to do source installs, fixes #26

Jordi Boggiano 13 years ago
parent
commit
6b6d6b6d82

+ 1 - 1
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());

+ 8 - 0
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(<<<EOT
 The <info>install</info> 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)

+ 1 - 1
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;
     }

+ 4 - 4
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');