diff --git a/src/Command/NormalizeCommand.php b/src/Command/NormalizeCommand.php index 8879f948..69ea6e7e 100644 --- a/src/Command/NormalizeCommand.php +++ b/src/Command/NormalizeCommand.php @@ -240,6 +240,15 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O $this->resetComposer(); + $file = $input->getArgument('file'); + + if (\is_string($file)) { + return $this->updateLockerInWorkingDirectory( + $output, + \dirname($file) + ); + } + return $this->updateLocker($output); } @@ -382,4 +391,30 @@ private function updateLocker(Console\Output\OutputInterface $output): int $output ); } + + /** + * @see https://getcomposer.org/doc/03-cli.md#update + * + * @param Console\Output\OutputInterface $output + * @param string $workingDirectory + * + * @throws \Exception + * + * @return int + */ + private function updateLockerInWorkingDirectory(Console\Output\OutputInterface $output, string $workingDirectory): int + { + return $this->getApplication()->run( + new Console\Input\ArrayInput([ + 'command' => 'update', + '--lock' => true, + '--no-autoloader' => true, + '--no-plugins' => true, + '--no-scripts' => true, + '--no-suggest' => true, + '--working-dir' => $workingDirectory, + ]), + $output + ); + } }