1212namespace Symfony \Flex \Command ;
1313
1414use Composer \Command \BaseCommand ;
15+ use Composer \IO \IOInterface ;
1516use Composer \Util \HttpDownloader ;
1617use Symfony \Component \Console \Exception \RuntimeException ;
1718use Symfony \Component \Console \Formatter \OutputFormatterStyle ;
2324use Symfony \Flex \Flex ;
2425use Symfony \Flex \GithubApi ;
2526use Symfony \Flex \InformationOperation ;
27+ use Symfony \Flex \Lock ;
2628use Symfony \Flex \Recipe ;
2729use Symfony \Flex \Update \RecipePatcher ;
2830use Symfony \Flex \Update \RecipeUpdate ;
@@ -52,7 +54,7 @@ protected function configure()
5254 $ this ->setName ('symfony:recipes:update ' )
5355 ->setAliases (['recipes:update ' ])
5456 ->setDescription ('Updates an already-installed recipe to the latest version. ' )
55- ->addArgument ('package ' , InputArgument::REQUIRED , 'Recipe that should be updated. ' )
57+ ->addArgument ('package ' , InputArgument::OPTIONAL , 'Recipe that should be updated. ' )
5658 ;
5759 }
5860
@@ -67,6 +69,16 @@ protected function execute(InputInterface $input, OutputInterface $output): int
6769
6870 $ packageName = $ input ->getArgument ('package ' );
6971 $ symfonyLock = $ this ->flex ->getLock ();
72+ if (!$ packageName ) {
73+ $ packageName = $ this ->askForPackage ($ io , $ symfonyLock );
74+
75+ if (null === $ packageName ) {
76+ $ io ->writeError ('All packages appear to be up-to-date! ' );
77+
78+ return 0 ;
79+ }
80+ }
81+
7082 if (!$ symfonyLock ->has ($ packageName )) {
7183 $ io ->writeError ([
7284 'Package not found inside symfony.lock. It looks like it \'s not installed? ' ,
@@ -293,4 +305,49 @@ private function generateChangelog(Recipe $originalRecipe): ?array
293305
294306 return $ lines ;
295307 }
308+
309+ private function askForPackage (IOInterface $ io , Lock $ symfonyLock ): ?string
310+ {
311+ $ installedRepo = $ this ->getComposer ()->getRepositoryManager ()->getLocalRepository ();
312+ $ locker = $ this ->getComposer ()->getLocker ();
313+ $ lockData = $ locker ->getLockData ();
314+
315+ // Merge all packages installed
316+ $ packages = array_merge ($ lockData ['packages ' ], $ lockData ['packages-dev ' ]);
317+
318+ $ operations = [];
319+ foreach ($ packages as $ value ) {
320+ if (null === $ pkg = $ installedRepo ->findPackage ($ value ['name ' ], '* ' )) {
321+ continue ;
322+ }
323+
324+ $ operations [] = new InformationOperation ($ pkg );
325+ }
326+
327+ $ recipes = $ this ->flex ->fetchRecipes ($ operations , false );
328+ ksort ($ recipes );
329+
330+ $ outdatedRecipes = [];
331+ foreach ($ recipes as $ name => $ recipe ) {
332+ $ lockRef = $ symfonyLock ->get ($ name )['recipe ' ]['ref ' ] ?? null ;
333+
334+ if (null !== $ lockRef && $ recipe ->getRef () !== $ lockRef && !$ recipe ->isAuto ()) {
335+ $ outdatedRecipes [] = $ name ;
336+ }
337+ }
338+
339+ if (0 === \count ($ outdatedRecipes )) {
340+ return null ;
341+ }
342+
343+ $ question = 'Which outdated recipe would you like to update? ' ;
344+
345+ $ choice = $ io ->select (
346+ $ question ,
347+ $ outdatedRecipes ,
348+ null
349+ );
350+
351+ return $ outdatedRecipes [$ choice ];
352+ }
296353}
0 commit comments