Skip to content

Commit

Permalink
CLI-822: Add --task-wait option to API commands
Browse files Browse the repository at this point in the history
  • Loading branch information
danepowell committed Nov 15, 2024
1 parent 489a8b4 commit 1029fdd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/Command/Api/ApiBaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Check warning on line 135 in src/Command/Api/ApiBaseCommand.php

View check run for this annotation

Codecov / codecov/patch

src/Command/Api/ApiBaseCommand.php#L133-L135

Added lines #L133 - L135 were not covered by tests
}

public function setMethod(string $method): void
Expand Down
5 changes: 5 additions & 0 deletions src/Command/Api/ApiCommandHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'])) {

Check warning on line 104 in src/Command/Api/ApiCommandHelper.php

View workflow job for this annotation

GitHub Actions / Mutation Testing

Escaped Mutant for Mutator "DecrementInteger": --- Original +++ New @@ @@ $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'])) { + if (array_key_exists('responses', $schema) && array_key_exists(201, $schema['responses'])) { $inputDefinition[] = new InputOption('task-wait', null, InputOption::VALUE_NONE, 'Wait for this task to complete'); } $command->setDefinition(new InputDefinition($inputDefinition));

Check warning on line 104 in src/Command/Api/ApiCommandHelper.php

View workflow job for this annotation

GitHub Actions / Mutation Testing

Escaped Mutant for Mutator "IncrementInteger": --- Original +++ New @@ @@ $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'])) { + if (array_key_exists('responses', $schema) && array_key_exists(203, $schema['responses'])) { $inputDefinition[] = new InputOption('task-wait', null, InputOption::VALUE_NONE, 'Wait for this task to complete'); } $command->setDefinition(new InputDefinition($inputDefinition));

Check warning on line 104 in src/Command/Api/ApiCommandHelper.php

View workflow job for this annotation

GitHub Actions / Mutation Testing

Escaped Mutant for Mutator "LogicalAndAllSubExprNegation": --- Original +++ New @@ @@ $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'])) { + 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));

Check warning on line 104 in src/Command/Api/ApiCommandHelper.php

View workflow job for this annotation

GitHub Actions / Mutation Testing

Escaped Mutant for Mutator "LogicalAnd": --- Original +++ New @@ @@ $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'])) { + 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));

Check warning on line 104 in src/Command/Api/ApiCommandHelper.php

View workflow job for this annotation

GitHub Actions / Mutation Testing

Escaped Mutant for Mutator "LogicalAndNegation": --- Original +++ New @@ @@ $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'])) { + 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));

Check warning on line 104 in src/Command/Api/ApiCommandHelper.php

View workflow job for this annotation

GitHub Actions / Mutation Testing

Escaped Mutant for Mutator "LogicalAndSingleSubExprNegation": --- Original +++ New @@ @@ $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'])) { + 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));

Check warning on line 104 in src/Command/Api/ApiCommandHelper.php

View workflow job for this annotation

GitHub Actions / Mutation Testing

Escaped Mutant for Mutator "LogicalAndSingleSubExprNegation": --- Original +++ New @@ @@ $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'])) { + 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));
$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));
Expand Down

0 comments on commit 1029fdd

Please sign in to comment.