Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions dev/google-cloud
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ if (!file_exists(__DIR__ . '/vendor/autoload.php')) {
require __DIR__ . '/vendor/autoload.php';

use Google\Cloud\Dev\Command\ComponentAddVersionCommand;
use Google\Cloud\Dev\Command\ComponentExecuteCommand;
use Google\Cloud\Dev\Command\ComponentInfoCommand;
use Google\Cloud\Dev\Command\ComponentNewCommand;
use Google\Cloud\Dev\Command\ComponentUpdateGencodeCommand;
Expand All @@ -48,6 +49,7 @@ $rootDirectory = realpath(__DIR__ . '/../') . '/';
$app = new Application;
$app->add(new ComponentInfoCommand());
$app->add(new ComponentAddVersionCommand($rootDirectory));
$app->add(new ComponentExecuteCommand());
$app->add(new ComponentNewCommand($rootDirectory));
$app->add(new ComponentUpdateGencodeCommand($rootDirectory));
$app->add(new ComponentUpdateReadmeSampleCommand($rootDirectory));
Expand Down
65 changes: 65 additions & 0 deletions dev/src/Command/ComponentExecuteCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php
/**
* Copyright 2026 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

namespace Google\Cloud\Dev\Command;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Output\OutputInterface;
use Google\Cloud\Dev\Component;

/**
* Execute commands for every Component
*
* ```bash
* // execute PHP code directly (don't forget to escape `$` for bash
* ./dev/google-cloud component:execute "copy('SECURITY.md', \$component->getPath() . '/SECURITY.md');"
* // execute a PHP file (don't forget to escape `$` for bash
* ./dev/google-cloud component:execute copy_file.php
* ```
*
* @internal
*/
class ComponentExecuteCommand extends Command
{
protected function configure()
{
$this->setName('component:execute')
->setDescription('Execute a command for each component')
->addArgument('code', InputArgument::REQUIRED, 'Path to a file or PHP code to execute')
;
}

protected function execute(InputInterface $input, OutputInterface $output): int
{
$code = $input->getArgument('code');
$components = Component::getComponents();

$codeToExecute = file_exists($code) ? file_get_contents($code) : $code;
if (0 === strpos($codeToExecute, '<?php')) {
$codeToExecute = substr($codeToExecute, 5);
}
$output->writeln('<info>' . $codeToExecute . '</>');
foreach ($components as $component) {
$output->writeln('Executing for ' . $component->getName());
eval($codeToExecute);
}

return 0;
}
}
Loading