OutdatedCommand.php 3.5 KB

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