diff --git a/src/Command/Api/ApiBaseCommand.php b/src/Command/Api/ApiBaseCommand.php index 8f3fc52ea..1ea39130d 100644 --- a/src/Command/Api/ApiBaseCommand.php +++ b/src/Command/Api/ApiBaseCommand.php @@ -12,6 +12,7 @@ use Closure; use GuzzleHttp\Psr7\Utils; use Symfony\Component\Console\Attribute\AsCommand; +use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -126,7 +127,12 @@ protected function execute(InputInterface $input, OutputInterface $output): int $contents = json_encode($response, JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT); $this->output->writeln($contents); - return $exitCode; + if (!$this->getParamFromInput($input, 'task-wait')) { + return $exitCode; + } + $notificationUuid = CommandBase::getNotificationUuidFromResponse($response); + $success = $this->waitForNotificationToComplete($this->cloudApiClientService->getClient(), $notificationUuid, "Waiting for task $notificationUuid to complete"); + return $success ? Command::SUCCESS : Command::FAILURE; } public function setMethod(string $method): void diff --git a/src/Command/Api/ApiCommandHelper.php b/src/Command/Api/ApiCommandHelper.php index 70082ff0c..f1c4f3d1f 100644 --- a/src/Command/Api/ApiCommandHelper.php +++ b/src/Command/Api/ApiCommandHelper.php @@ -100,6 +100,11 @@ private function addApiCommandParameters(array $schema, array $acquiaCloudSpec, $inputDefinition = array_merge($inputDefinition, $bodyInputDefinition); } + // Add --task-wait parameter for responses with notifications. + if (array_key_exists('responses', $schema) && array_key_exists(202, $schema['responses'])) { + $inputDefinition[] = new InputOption('task-wait', null, InputOption::VALUE_NONE, 'Wait for this task to complete'); + } + $command->setDefinition(new InputDefinition($inputDefinition)); if ($usage) { $command->addUsage(rtrim($usage));