Completed
Push — master ( 5f7b96...a034ab )
by GBProd
02:49
created

ListAliasCommand::execute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 19
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 19
ccs 13
cts 13
cp 1
rs 9.4285
cc 2
eloc 11
nc 2
nop 2
crap 2
1
<?php
2
3
namespace GBProd\ElasticaExtraBundle\Command;
4
5
use Symfony\Component\Console\Input\InputArgument;
6
use Symfony\Component\Console\Input\InputInterface;
7
use Symfony\Component\Console\Input\InputOption;
8
use Symfony\Component\Console\Output\OutputInterface;
9
10
/**
11
 * Command to list aliases
12
 *
13
 * @author gbprod <[email protected]>
14
 */
15
class ListAliasCommand extends ElasticaAwareCommand
16
{
17
    /**
18
     * {@inheritdoc}
19
     */
20 1
    protected function configure()
21
    {
22 1
        $this
23 1
            ->setName('elasticsearch:alias:list')
24 1
            ->setDescription('List index aliases')
25 1
            ->addArgument('index', InputArgument::REQUIRED, 'Which index ?')
26 1
            ->addOption('client', null, InputOption::VALUE_REQUIRED, 'Client to use (if not default)', null)
27
        ;
28 1
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33 1
    protected function execute(InputInterface $input, OutputInterface $output)
34
    {
35 1
        $client = $this->getClient($input->getOption('client'));
36 1
        $index  = $input->getArgument('index');
37
38 1
        $output->writeln(sprintf(
39 1
            '<info>Aliases for index <comment>%s</comment></info>',
40
            $index
41 1
        ));
42
43
        $aliases = $client
44 1
            ->getIndex($index)
45 1
            ->getAliases()
46 1
        ;
47
48 1
        foreach ($aliases as $alias) {
49 1
            $output->writeln(' * ' . $alias);
50 1
        }
51 1
    }
52
}
53