Skip to content

Commit

Permalink
allow specifying a component, fix add
Browse files Browse the repository at this point in the history
  • Loading branch information
bshaffer committed Nov 13, 2023
1 parent d958ea4 commit b58d90c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
12 changes: 8 additions & 4 deletions dev/src/Command/UpdateDepsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

/**
* Update package dependencies
*
* @internal
*/
class UpdateDepsCommand extends Command
Expand All @@ -37,9 +38,9 @@ protected function configure()
->setDescription('update a dependency across all components')
->addArgument('package', InputArgument::REQUIRED, 'Package name to update, e.g. "google/gax"')
->addArgument('version', InputArgument::OPTIONAL, 'Package version to update to, e.g. "1.4.0"', '')
->addOption('file', 'f', InputOption::VALUE_REQUIRED|InputOption::VALUE_IS_ARRAY, 'bumps deps for a single composer file')
->addOption('component', 'c', InputOption::VALUE_REQUIRED|InputOption::VALUE_IS_ARRAY, 'bumps deps for the specified component/file')
->addOption('bump', '', InputOption::VALUE_NONE, 'Bump to latest version of the package')
->addOption('add', '', InputOption::VALUE_OPTIONAL, 'Adds the dep if it doesn\'t exist (--add=dev for require-dev)')
->addOption('add', '', InputOption::VALUE_OPTIONAL, 'Adds the dep if it doesn\'t exist (--add=dev for require-dev)', false)
->addOption('local', '', InputOption::VALUE_NONE, 'Add a link to the local component')
;
}
Expand All @@ -65,13 +66,16 @@ protected function execute(InputInterface $input, OutputInterface $output)

$componentPath = $input->getOption('local') ? $this->getComponentName($paths, $package) : null;
$updateCount = 0;
foreach ($input->getOption('file') ?: $paths as $jsonFile) {
foreach ($input->getOption('component') ?: $paths as $jsonFile) {
if (is_dir($jsonFile) && file_exists($jsonFile . '/composer.json')) {
$jsonFile .= '/composer.json';
}
$composerJson = json_decode(file_get_contents($jsonFile), true);
$require = 'require';
if (!isset($composerJson['require'][$package])) {
if (isset($composerJson['require-dev'][$package])) {
$require = 'require-dev';
} elseif (!$input->getOption('add')) {
} elseif (false === $input->getOption('add')) {
continue;
} elseif ('dev' === $input->getOption('add')) {
$require = 'require-dev';
Expand Down
2 changes: 1 addition & 1 deletion dev/tests/Unit/Command/UpdateDepsCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function testUpdateDeps(array $cmdOptions, array $json, array $expectedJs
{
$tmpFile = sys_get_temp_dir() . '/composer.json';
file_put_contents($tmpFile, json_encode($json));
$cmdOptions['--file'] = [$tmpFile];
$cmdOptions['--component'] = [$tmpFile];
$commandTester = new CommandTester(new UpdateDepsCommand());
$commandTester->execute($cmdOptions);

Expand Down

0 comments on commit b58d90c

Please sign in to comment.