OutdatedCommand.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. new InputOption('strict', null, InputOption::VALUE_NONE, 'Return a non-zero exit code when there are outdated packages'),
  33. new InputOption('minor-only', 'm', InputOption::VALUE_NONE, 'Show only packages that have minor SemVer-compatible updates. Use with the --outdated option.'),
  34. ))
  35. ->setHelp(<<<EOT
  36. The outdated command is just a proxy for `composer show -l`
  37. The color coding (or signage if you have ANSI colors disabled) for dependency versions is as such:
  38. - <info>green</info> (=): Dependency is in the latest version and is up to date.
  39. - <comment>yellow</comment> (~): Dependency has a new version available that includes backwards
  40. compatibility breaks according to semver, so upgrade when you can but it
  41. may involve work.
  42. - <highlight>red</highlight> (!): Dependency has a new version that is semver-compatible and you should upgrade it.
  43. EOT
  44. )
  45. ;
  46. }
  47. protected function execute(InputInterface $input, OutputInterface $output)
  48. {
  49. $args = array(
  50. 'show',
  51. '--latest' => true,
  52. );
  53. if (!$input->getOption('all')) {
  54. $args['--outdated'] = true;
  55. }
  56. if ($input->getOption('direct')) {
  57. $args['--direct'] = true;
  58. }
  59. if ($input->getArgument('package')) {
  60. $args['package'] = $input->getArgument('package');
  61. }
  62. if ($input->getOption('strict')) {
  63. $args['--strict'] = true;
  64. }
  65. if ($input->getOption('minor-only')) {
  66. $args['--minor-only'] = true;
  67. }
  68. $input = new ArrayInput($args);
  69. return $this->getApplication()->run($input, $output);
  70. }
  71. /**
  72. * {@inheritDoc}
  73. */
  74. public function isProxyCommand()
  75. {
  76. return true;
  77. }
  78. }