diff --git a/src/Composer/Command/InstallCommand.php b/src/Composer/Command/InstallCommand.php index fa64cbf34..33dd826db 100644 --- a/src/Composer/Command/InstallCommand.php +++ b/src/Composer/Command/InstallCommand.php @@ -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(<<install 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'); } diff --git a/src/Composer/Command/UpdateCommand.php b/src/Composer/Command/UpdateCommand.php index 90573a872..4af6fbb4d 100644 --- a/src/Composer/Command/UpdateCommand.php +++ b/src/Composer/Command/UpdateCommand.php @@ -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(<<update 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); } } diff --git a/src/Composer/DependencyResolver/Operation/InstallOperation.php b/src/Composer/DependencyResolver/Operation/InstallOperation.php index 89ab5bd85..98e8d8de6 100644 --- a/src/Composer/DependencyResolver/Operation/InstallOperation.php +++ b/src/Composer/DependencyResolver/Operation/InstallOperation.php @@ -55,4 +55,12 @@ class InstallOperation extends SolverOperation { return 'install'; } + + /** + * {@inheritDoc} + */ + public function __toString() + { + return 'Installing '.$this->package; + } } diff --git a/src/Composer/DependencyResolver/Operation/OperationInterface.php b/src/Composer/DependencyResolver/Operation/OperationInterface.php index 704de2d5d..5c819cab8 100644 --- a/src/Composer/DependencyResolver/Operation/OperationInterface.php +++ b/src/Composer/DependencyResolver/Operation/OperationInterface.php @@ -34,4 +34,11 @@ interface OperationInterface * @return string */ function getReason(); + + /** + * Serializes the operation in a human readable format + * + * @return string + */ + function __toString(); } diff --git a/src/Composer/DependencyResolver/Operation/UninstallOperation.php b/src/Composer/DependencyResolver/Operation/UninstallOperation.php index 3731f3181..ddc8190e5 100644 --- a/src/Composer/DependencyResolver/Operation/UninstallOperation.php +++ b/src/Composer/DependencyResolver/Operation/UninstallOperation.php @@ -55,4 +55,12 @@ class UninstallOperation extends SolverOperation { return 'uninstall'; } + + /** + * {@inheritDoc} + */ + public function __toString() + { + return 'Uninstalling '.$this->package; + } } diff --git a/src/Composer/DependencyResolver/Operation/UpdateOperation.php b/src/Composer/DependencyResolver/Operation/UpdateOperation.php index c9d75c7b4..ccaaf82ec 100644 --- a/src/Composer/DependencyResolver/Operation/UpdateOperation.php +++ b/src/Composer/DependencyResolver/Operation/UpdateOperation.php @@ -68,4 +68,12 @@ class UpdateOperation extends SolverOperation { return 'update'; } + + /** + * {@inheritDoc} + */ + public function __toString() + { + return 'Updating '.$this->initialPackage.' to '.$this->targetPackage; + } }