OutdatedCommand.php 3.8 KB

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