|
16 | 16 | use Composer\Util\HttpDownloader;
|
17 | 17 | use Symfony\Component\Console\Input\InputArgument;
|
18 | 18 | use Symfony\Component\Console\Input\InputInterface;
|
| 19 | +use Symfony\Component\Console\Input\InputOption; |
19 | 20 | use Symfony\Component\Console\Output\OutputInterface;
|
20 | 21 | use Symfony\Flex\InformationOperation;
|
21 | 22 | use Symfony\Flex\Lock;
|
@@ -49,6 +50,7 @@ protected function configure()
|
49 | 50 | ->setDefinition([
|
50 | 51 | new InputArgument('package', InputArgument::OPTIONAL, 'Package to inspect, if not provided all packages are.'),
|
51 | 52 | ])
|
| 53 | + ->addOption('outdated', 'o', InputOption::VALUE_NONE, 'Show only recipes that are outdated') |
52 | 54 | ;
|
53 | 55 | }
|
54 | 56 |
|
@@ -96,35 +98,51 @@ protected function execute(InputInterface $input, OutputInterface $output)
|
96 | 98 | return 0;
|
97 | 99 | }
|
98 | 100 |
|
99 |
| - // display a resume of all packages |
100 |
| - $write = [ |
101 |
| - '', |
102 |
| - '<bg=blue;fg=white> </>', |
103 |
| - '<bg=blue;fg=white> Available recipes. </>', |
104 |
| - '<bg=blue;fg=white> </>', |
105 |
| - '', |
106 |
| - ]; |
| 101 | + $outdated = $input->getOption('outdated'); |
107 | 102 |
|
| 103 | + $write = []; |
| 104 | + $hasOutdatedRecipes = false; |
108 | 105 | /** @var Recipe $recipe */
|
109 | 106 | foreach ($recipes as $name => $recipe) {
|
110 | 107 | $lockRef = $this->symfonyLock->get($name)['recipe']['ref'] ?? null;
|
111 | 108 |
|
112 |
| - $additional = ''; |
| 109 | + $additional = null; |
113 | 110 | if (null === $lockRef && null !== $recipe->getRef()) {
|
114 | 111 | $additional = '<comment>(recipe not installed)</comment>';
|
115 | 112 | } elseif ($recipe->getRef() !== $lockRef) {
|
116 | 113 | $additional = '<comment>(update available)</comment>';
|
117 | 114 | }
|
| 115 | + |
| 116 | + if ($outdated && null === $additional) { |
| 117 | + continue; |
| 118 | + } |
| 119 | + |
| 120 | + $hasOutdatedRecipes = true; |
118 | 121 | $write[] = sprintf(' * %s %s', $name, $additional);
|
119 | 122 | }
|
120 | 123 |
|
121 |
| - $write[] = ''; |
122 |
| - $write[] = 'Run:'; |
123 |
| - $write[] = ' * <info>composer recipes vendor/package</info> to see details about a recipe.'; |
124 |
| - $write[] = ' * <info>composer recipes:install vendor/package --force -v</info> to update that recipe.'; |
125 |
| - $write[] = ''; |
| 124 | + // Nothing to display |
| 125 | + if (!$hasOutdatedRecipes) { |
| 126 | + return 0; |
| 127 | + } |
126 | 128 |
|
127 |
| - $this->getIO()->write($write); |
| 129 | + $this->getIO()->write(array_merge([ |
| 130 | + '', |
| 131 | + '<bg=blue;fg=white> </>', |
| 132 | + sprintf('<bg=blue;fg=white> %s recipes. </>', $outdated ? ' Outdated' : 'Available'), |
| 133 | + '<bg=blue;fg=white> </>', |
| 134 | + '', |
| 135 | + ], $write, [ |
| 136 | + '', |
| 137 | + 'Run:', |
| 138 | + ' * <info>composer recipes vendor/package</info> to see details about a recipe.', |
| 139 | + ' * <info>composer recipes:install vendor/package --force -v</info> to update that recipe.', |
| 140 | + '', |
| 141 | + ])); |
| 142 | + |
| 143 | + if ($outdated) { |
| 144 | + return 1; |
| 145 | + } |
128 | 146 |
|
129 | 147 | return 0;
|
130 | 148 | }
|
|
0 commit comments