UpdateCommand.php 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. /*
  3. * This file is part of Composer.
  4. *
  5. * (c) Nils Adermann <naderman@naderman.de>
  6. * Jordi Boggiano <j.boggiano@seld.be>
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. namespace Composer\Command;
  12. use Composer\Installer;
  13. use Symfony\Component\Console\Input\InputInterface;
  14. use Symfony\Component\Console\Input\InputOption;
  15. use Symfony\Component\Console\Input\InputArgument;
  16. use Symfony\Component\Console\Output\OutputInterface;
  17. /**
  18. * @author Jordi Boggiano <j.boggiano@seld.be>
  19. */
  20. class UpdateCommand extends Command
  21. {
  22. protected function configure()
  23. {
  24. $this
  25. ->setName('update')
  26. ->setDescription('Updates your dependencies to the latest version, and updates the composer.lock file.')
  27. ->setDefinition(array(
  28. new InputArgument('packages', InputArgument::IS_ARRAY | InputArgument::OPTIONAL, 'Packages that should be updated, if not provided all packages are.'),
  29. new InputOption('prefer-source', null, InputOption::VALUE_NONE, 'Forces installation from package sources when possible, including VCS information.'),
  30. new InputOption('prefer-dist', null, InputOption::VALUE_NONE, 'Forces installation from package dist even for dev versions.'),
  31. new InputOption('dry-run', null, InputOption::VALUE_NONE, 'Outputs the operations but will not execute anything (implicitly enables --verbose).'),
  32. new InputOption('dev', null, InputOption::VALUE_NONE, 'Enables installation of dev-require packages.'),
  33. new InputOption('no-custom-installers', null, InputOption::VALUE_NONE, 'Disables all custom installers.'),
  34. new InputOption('no-scripts', null, InputOption::VALUE_NONE, 'Skips the execution of all scripts defined in composer.json file.'),
  35. new InputOption('verbose', 'v', InputOption::VALUE_NONE, 'Shows more details including new commits pulled in when updating packages.'),
  36. ))
  37. ->setHelp(<<<EOT
  38. The <info>update</info> command reads the composer.json file from the
  39. current directory, processes it, and updates, removes or installs all the
  40. dependencies.
  41. <info>php composer.phar update</info>
  42. To limit the update operation to a few packages, you can list the package(s)
  43. you want to update as such:
  44. <info>php composer.phar update vendor/package1 foo/mypackage [...]</info>
  45. EOT
  46. )
  47. ;
  48. }
  49. protected function execute(InputInterface $input, OutputInterface $output)
  50. {
  51. $composer = $this->getComposer();
  52. $io = $this->getIO();
  53. $install = Installer::create($io, $composer);
  54. $install
  55. ->setDryRun($input->getOption('dry-run'))
  56. ->setVerbose($input->getOption('verbose'))
  57. ->setPreferSource($input->getOption('prefer-source'))
  58. ->setPreferDist($input->getOption('prefer-dist'))
  59. ->setDevMode($input->getOption('dev'))
  60. ->setRunScripts(!$input->getOption('no-scripts'))
  61. ->setUpdate(true)
  62. ->setUpdateWhitelist($input->getArgument('packages'))
  63. ;
  64. if ($input->getOption('no-custom-installers')) {
  65. $install->disableCustomInstallers();
  66. }
  67. return $install->run() ? 0 : 1;
  68. }
  69. }