Skip to content

Commit 446f0df

Browse files
feature #707 New flag to list only outdated recipes (maxhelias)
This PR was merged into the 1.9-dev branch. Discussion ---------- New flag to list only outdated recipes Re-open #668 Commits ------- 48ba230 New flag to list only outdated recipes
2 parents 7d0403a + 48ba230 commit 446f0df

File tree

1 file changed

+33
-15
lines changed

1 file changed

+33
-15
lines changed

src/Command/RecipesCommand.php

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Composer\Util\HttpDownloader;
1717
use Symfony\Component\Console\Input\InputArgument;
1818
use Symfony\Component\Console\Input\InputInterface;
19+
use Symfony\Component\Console\Input\InputOption;
1920
use Symfony\Component\Console\Output\OutputInterface;
2021
use Symfony\Flex\InformationOperation;
2122
use Symfony\Flex\Lock;
@@ -49,6 +50,7 @@ protected function configure()
4950
->setDefinition([
5051
new InputArgument('package', InputArgument::OPTIONAL, 'Package to inspect, if not provided all packages are.'),
5152
])
53+
->addOption('outdated', 'o', InputOption::VALUE_NONE, 'Show only recipes that are outdated')
5254
;
5355
}
5456

@@ -96,35 +98,51 @@ protected function execute(InputInterface $input, OutputInterface $output)
9698
return 0;
9799
}
98100

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');
107102

103+
$write = [];
104+
$hasOutdatedRecipes = false;
108105
/** @var Recipe $recipe */
109106
foreach ($recipes as $name => $recipe) {
110107
$lockRef = $this->symfonyLock->get($name)['recipe']['ref'] ?? null;
111108

112-
$additional = '';
109+
$additional = null;
113110
if (null === $lockRef && null !== $recipe->getRef()) {
114111
$additional = '<comment>(recipe not installed)</comment>';
115112
} elseif ($recipe->getRef() !== $lockRef) {
116113
$additional = '<comment>(update available)</comment>';
117114
}
115+
116+
if ($outdated && null === $additional) {
117+
continue;
118+
}
119+
120+
$hasOutdatedRecipes = true;
118121
$write[] = sprintf(' * %s %s', $name, $additional);
119122
}
120123

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+
}
126128

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+
}
128146

129147
return 0;
130148
}

0 commit comments

Comments
 (0)