AddCommand::configure()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 7
rs 9.4285
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
/**
3
 * CRM library
4
 * @author Tao <[email protected]>
5
 */
6
namespace Slince\Crm\Command;
7
8
use Slince\Crm\ConfigPath;
9
use Symfony\Component\Console\Input\InputArgument;
10
use Symfony\Component\Console\Input\InputInterface;
11
use Symfony\Component\Console\Output\OutputInterface;
12
13
class AddCommand extends Command
14
{
15
    /**
16
     * Command name
17
     * @var string
18
     */
19
    const NAME = 'add';
20
21
    /**
22
     * {@inheritdoc}
23
     */
24
    public function configure()
25
    {
26
        $this->setName(static::NAME)
27
            ->setDescription('Add one custom registry')
28
            ->addArgument('registry-name', InputArgument::REQUIRED, 'The registry name')
29
            ->addArgument('registry-url', InputArgument::REQUIRED, 'The registry url');
30
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35
    public function execute(InputInterface $input, OutputInterface $output)
36
    {
37
        $registryName = $input->getArgument('registry-name');
38
        $registryUrl = $input->getArgument('registry-url');
39
        //Add registry & dump to config file
40
        $this->getManager()->addRegistry($registryName, $registryUrl);
41
        $this->getManager()->dumpRepositoriesToFile(ConfigPath::getUserConfigFile());
42
43
        $output->writeln("<info>Add registry [{$registryName}] success</info>");
44
    }
45
}
46