OutdatedCommand.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 Symfony\Component\Console\Input\InputInterface;
  13. use Symfony\Component\Console\Input\InputArgument;
  14. use Symfony\Component\Console\Input\ArrayInput;
  15. use Symfony\Component\Console\Input\InputOption;
  16. use Symfony\Component\Console\Output\OutputInterface;
  17. /**
  18. * @author Jordi Boggiano <j.boggiano@seld.be>
  19. */
  20. class OutdatedCommand extends ShowCommand
  21. {
  22. protected function configure()
  23. {
  24. $this
  25. ->setName('outdated')
  26. ->setDescription('Shows a list of installed packages that have updates available, including their latest version.')
  27. ->setDefinition(array(
  28. new InputArgument('package', InputArgument::OPTIONAL, 'Package to inspect. Or a name including a wildcard (*) to filter lists of packages instead.'),
  29. new InputOption('outdated', 'o', InputOption::VALUE_NONE, 'Show only packages that are outdated (this is the default, but present here for compat with `show`'),
  30. new InputOption('all', 'a', InputOption::VALUE_NONE, 'Show all installed packages with their latest versions'),
  31. new InputOption('direct', 'D', InputOption::VALUE_NONE, 'Shows only packages that are directly required by the root package'),
  32. ))
  33. ->setHelp(<<<EOT
  34. The outdated command is just a proxy for `composer show -l`
  35. The color coding for dependency versions is as such:
  36. - <info>green</info>: Dependency is in the latest version and is up to date.
  37. - <comment>yellow</comment>: Dependency has a new version available that includes backwards
  38. compatibility breaks according to semver, so upgrade when you can but it
  39. may involve work.
  40. - <highlight>red</highlight>: Dependency has a new version that is semver-compatible and you should upgrade it.
  41. EOT
  42. )
  43. ;
  44. }
  45. protected function execute(InputInterface $input, OutputInterface $output)
  46. {
  47. $args = array(
  48. 'show',
  49. '--latest' => true,
  50. );
  51. if (!$input->getOption('all')) {
  52. $args['--outdated'] = true;
  53. }
  54. if ($input->getOption('direct')) {
  55. $args['--direct'] = true;
  56. }
  57. if ($input->getArgument('package')) {
  58. $args['package'] = $input->getArgument('package');
  59. }
  60. $input = new ArrayInput($args);
  61. return $this->getApplication()->run($input, $output);
  62. }
  63. /**
  64. * {@inheritDoc}
  65. */
  66. public function isProxyCommand()
  67. {
  68. return true;
  69. }
  70. }