Add --dry-run option and list all operations on --verbose

main
Jordi Boggiano 13 years ago
parent d020f2701d
commit f2662b193d

@ -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,19 +146,26 @@ 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();
$localRepo->write();
$output->writeln('> Generating autoload files');
$generator = new AutoloadGenerator;
$generator->dump($localRepo, $composer->getPackage(), $installationManager, $installationManager->getVendorPath().'/.composer');
$output->writeln('> Generating autoload files');
$generator = new AutoloadGenerator;
$generator->dump($localRepo, $composer->getPackage(), $installationManager, $installationManager->getVendorPath().'/.composer');
}
$output->writeln('> Done');
}

@ -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);
}
}

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

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

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

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

Loading…
Cancel
Save