1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Dandelion\Console\Command; |
6
|
|
|
|
7
|
|
|
use Dandelion\Operation\InitializerInterface; |
8
|
|
|
use InvalidArgumentException; |
9
|
|
|
use Symfony\Component\Console\Command\Command; |
10
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
11
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
12
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
13
|
|
|
|
14
|
|
|
class InitCommand extends Command |
15
|
|
|
{ |
16
|
|
|
public const NAME = 'init'; |
17
|
|
|
public const DESCRIPTION = 'Init split repository on vcs platform.'; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var \Dandelion\Operation\InitializerInterface |
21
|
|
|
*/ |
22
|
|
|
protected $initializer; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @param \Dandelion\Operation\InitializerInterface $initializer |
26
|
|
|
*/ |
27
|
|
|
public function __construct( |
28
|
|
|
InitializerInterface $initializer |
29
|
|
|
) { |
30
|
|
|
parent::__construct(); |
31
|
|
|
$this->initializer = $initializer; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @return void |
36
|
|
|
*/ |
37
|
|
|
protected function configure(): void |
38
|
|
|
{ |
39
|
|
|
parent::configure(); |
40
|
|
|
|
41
|
|
|
$this->setName(static::NAME); |
42
|
|
|
$this->setDescription(static::DESCRIPTION); |
43
|
|
|
|
44
|
|
|
$this->addArgument('repositoryName', InputArgument::REQUIRED, 'Name of split repository'); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @param \Symfony\Component\Console\Input\InputInterface $input |
49
|
|
|
* @param \Symfony\Component\Console\Output\OutputInterface $output |
50
|
|
|
* |
51
|
|
|
* @return int |
52
|
|
|
*/ |
53
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int |
54
|
|
|
{ |
55
|
|
|
$repositoryName = $input->getArgument('repositoryName'); |
56
|
|
|
|
57
|
|
|
if (!is_string($repositoryName)) { |
58
|
|
|
throw new InvalidArgumentException('Unsupported type for given argument'); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
$this->initializer->executeForSingleRepository($repositoryName); |
62
|
|
|
|
63
|
|
|
return 0; |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|