8000 Allowing specific recipes to be "re-installed" by weaverryan · Pull Request #583 · symfony/flex · GitHub
[go: up one dir, main page]

Skip to content

Allowing specific recipes to be "re-installed" #583

New issue

Have a question about this project? Sign up for a fre 10000 e GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 11, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 28 additions & 4 deletions src/Command/SyncRecipesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Composer\DependencyResolver\Operation\InstallOperation;
use Composer\Factory;
use Symfony\Component\Console\Exception\RuntimeException;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
Expand All @@ -39,6 +40,7 @@ protected function configure()
$this->setName('symfony:sync-recipes')
->setAliases(['sync-recipes', 'fix-recipes'])
->setDescription('Installs or reinstalls recipes for already installed packages.')
->addArgument('packages', InputArgument::IS_ARRAY | InputArgument::OPTIONAL, 'Recipes that should be installed.')
->addOption('force', null, InputOption::VALUE_NONE, 'Ignore the "symfony.lock" file and overwrite existing files')
;
}
Expand All @@ -58,24 +60,46 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$lockData = $locker->getLockData();

$packages = [];
$totalPackages = [];
foreach ($lockData['packages'] as $pkg) {
$totalPackages[] = $pkg['name'];
if ($force || !$symfonyLock->has($pkg['name'])) {
$packages[] = $pkg['name'];
}
}
foreach ($lockData['packages-dev'] as $pkg) {
$totalPackages[] = $pkg['name'];
if ($force || !$symfonyLock->has($pkg['name'])) {
$packages[] = $pkg['name'];
}
}

$io = $this->getIO();

if ($targetPackages = $input->getArgument('packages')) {
if ($invalidPackages = array_diff($targetPackages, $totalPackages)) {
$io->writeError(sprintf('<warning>Cannot update: some packages are not installed:</warning> %s', implode(', ', $invalidPackages)));

return 1;
}

if ($packagesRequiringForce = array_diff($targetPackages, $packages)) {
$io->writeError(sprintf('Recipe(s) already installed for: <info>%s</info>', implode(', ', $packagesRequiringForce)));
$io->writeError('Re-run the command with <info>--force</info> to re-install the recipes.');
$io->writeError('');
}

$packages = array_diff($targetPackages, $packagesRequiringForce);
}

if (!$packages) {
$io->writeError('No recipes to install.');

return 0;
}

$composer = $this->getComposer();
$installedRepo = $composer->getRepositoryManager()->getLocalRepository();
$io = $this->getIO();

$operations = [];
foreach ($packages as $package) {
Expand All @@ -102,9 +126,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int
if ($force) {
$output = [
'',
'<bg=blue;fg=white> </>',
'<bg=blue;fg=white> Config files are now reset to their initial state. </>',
'<bg=blue;fg=white> </>',
'<bg=blue;fg=white> </>',
'<bg=blue;fg=white> Files have been reset to the latest version of the recipe. </>',
'<bg=blue;fg=white> </>',
'',
' * Use <comment>git diff</> to inspect the changes.',
'',
Expand Down
0