Lines
100.00%
9 / 9
Functions and Methods
100.00%
3 / 3
Classes and Traits
100.00%
1 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| AppRequestCommand | 100.00% | 9 / 9 | 100.00% | 3 / 3 | 4 | 100.00% | 1 / 1 | |||
| __construct | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| configure | 100.00% | 2 / 2 | 100.00% | 1 / 1 | 1 | |||||
| execute | 100.00% | 6 / 6 | 100.00% | 1 / 1 | 2 | |||||
| sendAppRequest | n/a | 0 / 0 | n/a | 0 / 0 | 0 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | declare(strict_types=1); | |
| 4 | ||
| 5 | namespace Stewart\Runtime\Console; | |
| 6 | ||
| 7 | use Amp\ByteStream\StreamException; | |
| 8 | use Amp\CancelledException; | |
| 9 | use Stewart\Contracts\App\AppId; | |
| 10 | use Stewart\Contracts\Exception\StewartException; | |
| 11 | use Stewart\Contracts\Time\Duration; | |
| 12 | use Stewart\Runtime\Config\ConfigLoader; | |
| 13 | use Stewart\Runtime\Control\Client\ControlClient; | |
| 14 | use Stewart\Runtime\Control\Client\ControlTarget; | |
| 15 | use Stewart\Runtime\Control\Client\ControlTargetResolver; | |
| 16 | use Stewart\Runtime\Control\Protocol\Frame\CommandResult; | |
| 17 | use Symfony\Component\Console\Command\Command; | |
| 18 | use Symfony\Component\Console\Input\InputArgument; | |
| 19 | use Symfony\Component\Console\Input\InputInterface; | |
| 20 | use Symfony\Component\Console\Output\OutputInterface; | |
| 21 | use Throwable; | |
| 22 | ||
| 23 | abstract class AppRequestCommand extends ControlCommand | |
| 24 | { | |
| 25 | public function __construct( | |
| 26 | ConfigLoader $config, | |
| 27 | ControlTargetResolver $targets, | |
| 28 | protected readonly ControlClient $client, | |
| 29 | ) { | |
| 30 | parent::__construct($config, $targets); | |
| 31 | } | |
| 32 | ||
| 33 | protected function configure(): void | |
| 34 | { | |
| 35 | parent::configure(); | |
| 36 | $this->addArgument('app', InputArgument::REQUIRED, 'The automation ID, as shown by stewart status'); | |
| 37 | } | |
| 38 | ||
| 39 | protected function execute(InputInterface $input, OutputInterface $output): int | |
| 40 | { | |
| 41 | try { | |
| 42 | $result = $this->sendAppRequest($this->resolveControlTarget($input), new AppId($this->readStringArgument($input, 'app')), $this->parseTimeoutOption($input)); | |
| 43 | } catch (StewartException|StreamException|CancelledException $e) { | |
| 44 | $output->writeln('<error>' . $e->getMessage() . '</error>'); | |
| 45 | ||
| 46 | return Command::FAILURE; | |
| 47 | } | |
| 48 | ||
| 49 | $this->writeCommandResult($output, $result); | |
| 50 | ||
| 51 | return Command::SUCCESS; | |
| 52 | } | |
| 53 | ||
| 54 | /** @throws StewartException|Throwable */ | |
| 55 | abstract protected function sendAppRequest(ControlTarget $target, AppId $appId, Duration $timeout): CommandResult; | |
| 56 | } |