8000 Allowing specific recipes to be "re-installed" · symfony/flex@a9dad87 · GitHub
[go: up one dir, main page]

Skip to content

Commit a9dad87

Browse files
committed
Allowing specific recipes to be "re-installed"
1 parent 59b42aa commit a9dad87

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

src/Command/SyncRecipesCommand.php

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Composer\DependencyResolver\Operation\InstallOperation;
1616
use Composer\Factory;
1717
use Symfony\Component\Console\Exception\RuntimeException;
18+
use Symfony\Component\Console\Input\InputArgument;
1819
use Symfony\Component\Console\Input\InputInterface;
1920
use Symfony\Component\Console\Input\InputOption;
2021
use Symfony\Component\Console\Output\OutputInterface;
@@ -39,6 +40,7 @@ protected function configure()
3940
$this->setName('symfony:sync-recipes')
4041
->setAliases(['sync-recipes', 'fix-recipes'])
4142
->setDescription('Installs or reinstalls recipes for already installed packages.')
43+
->addArgument('packages', InputArgument::IS_ARRAY | InputArgument::OPTIONAL, 'Recipes that should be installed.')
4244
->addOption('force', null, InputOption::VALUE_NONE, 'Ignore the "symfony.lock" file and overwrite existing files')
4345
;
4446
}
@@ -58,24 +60,46 @@ protected function execute(InputInterface $input, OutputInterface $output): int
5860
$lockData = $locker->getLockData();
5961

6062
$packages = [];
63+
$totalPackages = [];
6164
foreach ($lockData['packages'] as $pkg) {
65+
$totalPackages[] = $pkg['name'];
6266
if ($force || !$symfonyLock->has($pkg['name'])) {
6367
$packages[] = $pkg['name'];
6468
}
6569
}
6670
foreach ($lockData['packages-dev'] as $pkg) {
71+
$totalPackages[] = $pkg['name'];
6772
if ($force || !$symfonyLock->has($pkg['name'])) {
6873
$packages[] = $pkg['name'];
6974
}
7075
}
7176

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+
7295
if (!$packages) {
96+
$io->writeError('No recipes to install.');
97+
7398
return 0;
7499
}
75100

76101
$composer = $this->getComposer();
77102
$installedRepo = $composer->getRepositoryManager()->getLocalRepository();
78-
$io = $this->getIO();
79103

80104
$operations = [];
81105
foreach ($packages as $package) {
@@ -102,9 +126,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int
102126
if ($force) {
103127
$output = [
104128
'',
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> </>',
108132
'',
109133
' * Use <comment>git diff</> to inspect the changes.',
110134
'',

0 commit comments

Comments
 (0)
0