15
15
use Composer \DependencyResolver \Operation \InstallOperation ;
16
16
use Composer \Factory ;
17
17
use Symfony \Component \Console \Exception \RuntimeException ;
18
+ use Symfony \Component \Console \Input \InputArgument ;
18
19
use Symfony \Component \Console \Input \InputInterface ;
19
20
use Symfony \Component \Console \Input \InputOption ;
20
21
use Symfony \Component \Console \Output \OutputInterface ;
@@ -39,6 +40,7 @@ protected function configure()
39
40
$ this ->setName ('symfony:sync-recipes ' )
40
41
->setAliases (['sync-recipes ' , 'fix-recipes ' ])
41
42
->setDescription ('Installs or reinstalls recipes for already installed packages. ' )
43
+ ->addArgument ('packages ' , InputArgument::IS_ARRAY | InputArgument::OPTIONAL , 'Recipes that should be installed. ' )
42
44
->addOption ('force ' , null , InputOption::VALUE_NONE , 'Ignore the "symfony.lock" file and overwrite existing files ' )
43
45
;
44
46
}
@@ -58,24 +60,46 @@ protected function execute(InputInterface $input, OutputInterface $output): int
58
60
$ lockData = $ locker ->getLockData ();
59
61
60
62
$ packages = [];
63
+ $ totalPackages = [];
61
64
foreach ($ lockData ['packages ' ] as $ pkg ) {
65
+ $ totalPackages [] = $ pkg ['name ' ];
62
66
if ($ force || !$ symfonyLock ->has ($ pkg ['name ' ])) {
63
67
$ packages [] = $ pkg ['name ' ];
64
68
}
65
69
}
66
70
foreach ($ lockData ['packages-dev ' ] as $ pkg ) {
71
+ $ totalPackages [] = $ pkg ['name ' ];
67
72
if ($ force || !$ symfonyLock ->has ($ pkg ['name ' ])) {
68
73
$ packages [] = $ pkg ['name ' ];
69
74
}
70
75
}
71
76
77
+ $ io = $ this ->getIO ();
78
+
79
+ if ($ targetPackages = $ input ->getArgument ('packages ' )) {
80
+ if ($ invalidPackages = array_diff ($ targetPackages , $ totalPackages )) {
81
+ $ io ->writeError (sprintf ('<warning>Cannot update: some packages are not installed:</warning> %s ' , implode (', ' , $ invalidPackages )));
82
+
83
+ return 1 ;
84
+ }
85
+
86
+ if ($ packagesRequiringForce = array_diff ($ targetPackages , $ packages )) {
87
+ $ io ->writeError (sprintf ('Recipe(s) already installed for: <info>%s</info> ' , implode (', ' , $ packagesRequiringForce )));
88
+ $ io ->writeError ('Re-run the command with <info>--force</info> to re-install the recipes. ' );
89
+ $ io ->writeError ('' );
90
+ }
91
+
92
+ $ packages = array_diff ($ targetPackages , $ packagesRequiringForce );
93
+ }
94
+
72
95
if (!$ packages ) {
96
+ $ io ->writeError ('No recipes to install. ' );
97
+
73
98
return 0 ;
74
99
}
75
100
76
101
$ composer = $ this ->getComposer ();
77
102
$ installedRepo = $ composer ->getRepositoryManager ()->getLocalRepository ();
78
- $ io = $ this ->getIO ();
79
103
80
104
$ operations = [];
81
105
foreach ($ packages as $ package ) {
@@ -102,9 +126,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int
102
126
if ($ force ) {
103
127
$ output = [
104
128
'' ,
105
- '<bg=blue;fg=white> </> ' ,
106
- '<bg=blue;fg=white> Config files are now reset to their initial state . </> ' ,
107
- '<bg=blue;fg=white> </> ' ,
129
+ '<bg=blue;fg=white> </> ' ,
130
+ '<bg=blue;fg=white> Files have been reset to the latest version of the recipe . </> ' ,
131
+ '<bg=blue;fg=white> </> ' ,
108
132
'' ,
109
133
' * Use <comment>git diff</> to inspect the changes. ' ,
110
134
'' ,
0 commit comments