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\InstallTools; |
12
|
|
|
|
13
|
|
|
final class InstallCommand extends Command |
14
|
|
|
{ |
15
|
|
|
use DefaultTag; |
16
|
|
|
use DefaultTargetDir; |
17
|
|
|
|
18
|
|
|
public const NAME = 'install'; |
19
|
|
|
|
20
|
|
|
private InstallTools $useCase; |
21
|
|
|
private Runner $runner; |
22
|
|
|
|
23
|
13 |
|
public function __construct(InstallTools $useCase, Runner $runner) |
24
|
|
|
{ |
25
|
13 |
|
parent::__construct(self::NAME); |
26
|
|
|
|
27
|
13 |
|
$this->useCase = $useCase; |
28
|
13 |
|
$this->runner = $runner; |
29
|
|
|
} |
30
|
|
|
|
31
|
13 |
|
protected function configure(): void |
32
|
|
|
{ |
33
|
13 |
|
$this->setDescription('Installs tools'); |
34
|
13 |
|
$this->addOption('dry-run', null, InputOption::VALUE_NONE, 'Output the command without executing it'); |
35
|
13 |
|
$this->addOption('target-dir', null, InputOption::VALUE_REQUIRED, 'The target installation directory', $this->defaultTargetDir()); |
36
|
13 |
|
$this->addOption('exclude-tag', 'e', InputOption::VALUE_REQUIRED|InputOption::VALUE_IS_ARRAY, 'Tool tags to exclude', $this->defaultExcludeTag()); |
37
|
13 |
|
$this->addOption('tag', 't', InputOption::VALUE_REQUIRED|InputOption::VALUE_IS_ARRAY, 'Tool tags to filter by', $this->defaultTag()); |
38
|
|
|
} |
39
|
|
|
|
40
|
4 |
|
protected function execute(InputInterface $input, OutputInterface $output): int |
41
|
|
|
{ |
42
|
4 |
|
return $this->runner->run(\call_user_func($this->useCase, new Filter($input->getOption('exclude-tag'), $input->getOption('tag')))); |
43
|
|
|
} |
44
|
|
|
} |
45
|
|
|
|