1
0
Fork 0

Merge pull request #123 from Seldaek/dryrun

Add --dry-run option and list all operations on --verbose
pull/126/merge
Nils Adermann 2011-11-21 09:05:39 -08:00
commit bf7ad0ac9f
6 changed files with 56 additions and 13 deletions

View File

@ -37,6 +37,7 @@ class InstallCommand extends Command
->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.'),
new InputOption('dry-run', null, InputOption::VALUE_NONE, 'Outputs the operations but will not execute anything (implicitly enables --verbose).'),
))
->setHelp(<<<EOT
The <info>install</info> command reads the composer.json file from the
@ -52,11 +53,14 @@ EOT
protected function execute(InputInterface $input, OutputInterface $output)
{
return $this->install($output, $input->getOption('dev'));
return $this->install($input, $output);
}
public function install(OutputInterface $output, $preferSource, $update = false)
public function install(InputInterface $input, OutputInterface $output, $update = false)
{
$preferSource = (Boolean) $input->getOption('dev');
$dryRun = (Boolean) $input->getOption('dry-run');
$verbose = $dryRun || $input->getOption('verbose');
$composer = $this->getComposer();
if ($preferSource) {
@ -142,20 +146,27 @@ EOT
// execute operations
foreach ($operations as $operation) {
$installationManager->execute($operation);
if ($verbose) {
$output->writeln((string) $operation);
}
if (!$dryRun) {
$installationManager->execute($operation);
}
}
if ($update || !$composer->getLocker()->isLocked()) {
$composer->getLocker()->lockPackages($localRepo->getPackages());
$output->writeln('> Locked');
if (!$dryRun) {
if ($update || !$composer->getLocker()->isLocked()) {
$composer->getLocker()->lockPackages($localRepo->getPackages());
$output->writeln('> Locked');
}
$localRepo->write();
$output->writeln('> Generating autoload files');
$generator = new AutoloadGenerator;
$generator->dump($localRepo, $composer->getPackage(), $installationManager, $installationManager->getVendorPath().'/.composer');
}
$localRepo->write();
$output->writeln('> Generating autoload files');
$generator = new AutoloadGenerator;
$generator->dump($localRepo, $composer->getPackage(), $installationManager, $installationManager->getVendorPath().'/.composer');
$output->writeln('> Done');
}
}

View File

@ -35,6 +35,7 @@ class UpdateCommand extends Command
->setDescription('Updates your dependencies to the latest version, and updates the composer.lock file.')
->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).'),
))
->setHelp(<<<EOT
The <info>update</info> command reads the composer.json file from the
@ -53,6 +54,6 @@ EOT
$composer = $this->getComposer();
$installCommand = $this->getApplication()->find('install');
return $installCommand->install($output, $input->getOption('dev'), true);
return $installCommand->install($input, $output, true);
}
}

View File

@ -55,4 +55,12 @@ class InstallOperation extends SolverOperation
{
return 'install';
}
/**
* {@inheritDoc}
*/
public function __toString()
{
return 'Installing '.$this->package;
}
}

View File

@ -34,4 +34,11 @@ interface OperationInterface
* @return string
*/
function getReason();
/**
* Serializes the operation in a human readable format
*
* @return string
*/
function __toString();
}

View File

@ -55,4 +55,12 @@ class UninstallOperation extends SolverOperation
{
return 'uninstall';
}
/**
* {@inheritDoc}
*/
public function __toString()
{
return 'Uninstalling '.$this->package;
}
}

View File

@ -68,4 +68,12 @@ class UpdateOperation extends SolverOperation
{
return 'update';
}
/**
* {@inheritDoc}
*/
public function __toString()
{
return 'Updating '.$this->initialPackage.' to '.$this->targetPackage;
}
}