Lines 57.14% 4 / 7
Functions and Methods 50.00% 1 / 2
Classes and Traits 0.00% 0 / 1
Name Lines Functions and Methods CRAP Classes and Traits
ReloadCommand 57.14% 4 / 7 50.00% 1 / 2 3.71 0.00% 0 / 1
 __construct 100.00% 1 / 1 100.00% 1 / 1 1
 execute 50.00% 3 / 6 0.00% 0 / 1 2.50
1<?php
2
3declare(strict_types=1);
4
5namespace Stewart\Runtime\Console;
6
7use Amp\ByteStream\StreamException;
8use Amp\CancelledException;
9use Stewart\Contracts\Exception\StewartException;
10use Stewart\Runtime\Config\ConfigLoader;
11use Stewart\Runtime\Control\Client\ControlClient;
12use Stewart\Runtime\Control\Client\ControlTargetResolver;
13use Symfony\Component\Console\Attribute\AsCommand;
14use Symfony\Component\Console\Command\Command;
15use Symfony\Component\Console\Input\InputInterface;
16use Symfony\Component\Console\Output\OutputInterface;
17
18#[AsCommand(name: self::NAME, description: 'Check the project, then restart every worker on the current code, keeping the Home Assistant session')]
19final class ReloadCommand extends ControlCommand
20{
21    public const string NAME = 'reload';
22
23    public function __construct(
24        ConfigLoader $config,
25        ControlTargetResolver $targets,
26        private readonly ControlClient $client,
27    ) {
28        parent::__construct($config, $targets);
29    }
30
31    protected function execute(InputInterface $input, OutputInterface $output): int
32    {
33        try {
34            $result = $this->client->requestReload($this->resolveControlTarget($input), $this->parseTimeoutOption($input));
35        } catch (StewartException|StreamException|CancelledException $e) {
36            $output->writeln('<error>' . $e->getMessage() . '</error>');
37
38            return Command::FAILURE;
39        }
40
41        $this->writeCommandResult($output, $result);
42
43        return Command::SUCCESS;
44    }
45}