12
12
namespace Symfony \Flex \Command ;
13
13
14
14
use Composer \Command \BaseCommand ;
15
+ use Composer \IO \IOInterface ;
15
16
use Composer \Util \HttpDownloader ;
16
17
use Symfony \Component \Console \Exception \RuntimeException ;
17
18
use Symfony \Component \Console \Formatter \OutputFormatterStyle ;
23
24
use Symfony \Flex \Flex ;
24
25
use Symfony \Flex \GithubApi ;
25
26
use Symfony \Flex \InformationOperation ;
27
+ use Symfony \Flex \Lock ;
26
28
use Symfony \Flex \Recipe ;
27
29
use Symfony \Flex \Update \RecipePatcher ;
28
30
use Symfony \Flex \Update \RecipeUpdate ;
@@ -52,7 +54,7 @@ protected function configure()
52
54
$ this ->setName ('symfony:recipes:update ' )
53
55
->setAliases (['recipes:update ' ])
54
56
->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. ' )
56
58
;
57
59
}
58
60
@@ -67,6 +69,16 @@ protected function execute(InputInterface $input, OutputInterface $output): int
67
69
68
70
$ packageName = $ input ->getArgument ('package ' );
69
71
$ 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
+
70
82
if (!$ symfonyLock ->has ($ packageName )) {
71
83
$ io ->writeError ([
72
84
'Package not found inside symfony.lock. It looks like it \'s not installed? ' ,
@@ -293,4 +305,49 @@ private function generateChangelog(Recipe $originalRecipe): ?array
293
305
294
306
return $ lines ;
295
307
}
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
+ }
296
353
}
0 commit comments