|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace Zalas\Toolbox\Cli\Command; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Component\Console\Command\Command; |
|
6
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
7
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
8
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
9
|
|
|
use Zalas\Toolbox\Runner\Runner; |
|
10
|
|
|
use Zalas\Toolbox\Tool\Filter; |
|
11
|
|
|
use Zalas\Toolbox\UseCase\TestTools; |
|
12
|
|
|
|
|
13
|
|
|
final class TestCommand extends Command |
|
14
|
|
|
{ |
|
15
|
|
|
use DefaultTag; |
|
16
|
|
|
use DefaultTargetDir; |
|
17
|
|
|
|
|
18
|
|
|
public const NAME = 'test'; |
|
19
|
|
|
|
|
20
|
|
|
private TestTools $useCase; |
|
21
|
|
|
private Runner $runner; |
|
22
|
|
|
|
|
23
|
12 |
|
public function __construct(TestTools $useCase, Runner $runner) |
|
24
|
|
|
{ |
|
25
|
12 |
|
parent::__construct(self::NAME); |
|
26
|
|
|
|
|
27
|
12 |
|
$this->useCase = $useCase; |
|
28
|
12 |
|
$this->runner = $runner; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
12 |
|
protected function configure(): void |
|
32
|
|
|
{ |
|
33
|
12 |
|
$this->setDescription('Runs basic tests to verify tools are installed'); |
|
34
|
12 |
|
$this->addOption('dry-run', null, InputOption::VALUE_NONE, 'Output the command without executing it'); |
|
35
|
12 |
|
$this->addOption('target-dir', null, InputOption::VALUE_REQUIRED, 'The target installation directory', $this->defaultTargetDir()); |
|
36
|
12 |
|
$this->addOption('exclude-tag', 'e', InputOption::VALUE_REQUIRED|InputOption::VALUE_IS_ARRAY, 'Tool tags to exclude', $this->defaultExcludeTag()); |
|
37
|
12 |
|
$this->addOption('tag', 't', InputOption::VALUE_REQUIRED|InputOption::VALUE_IS_ARRAY, 'Tool tags to filter by', $this->defaultTag()); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
3 |
|
protected function execute(InputInterface $input, OutputInterface $output): int |
|
41
|
|
|
{ |
|
42
|
3 |
|
return $this->runner->run(\call_user_func($this->useCase, new Filter($input->getOption('exclude-tag'), $input->getOption('tag')))); |
|
43
|
|
|
} |
|
44
|
|
|
} |
|
45
|
|
|
|