Completed
Pull Request — master (#18)
by GBProd
02:04
created

ListIndexCommand   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 2
c 1
b 0
f 1
lcom 0
cbo 6
dl 0
loc 29
ccs 13
cts 13
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 9 1
A execute() 0 10 1
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 indices
12
 *
13
 * @author gbprod <[email protected]>
14
 */
15
class ListIndexCommand extends ElasticaAwareCommand
16
{
17
    /**
18
     * {@inheritdoc}
19
     */
20 2
    protected function configure()
21
    {
22 2
        $this
23 2
            ->setName('elasticsearch:index:list')
24 2
            ->setDescription('Index list')
25 2
            ->addOption('pattern', '', InputOption::VALUE_REQUIRED, 'Index name filter pattern', null)
26 2
            ->addOption('client', null, InputOption::VALUE_REQUIRED, 'Client to use (if not default)', null)
27
        ;
28 2
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33 2
    protected function execute(InputInterface $input, OutputInterface $output)
34
    {
35 2
        $client = $this->getClient($input->getOption('client'));
36
37 2
        $uri = sprintf('_cat/indices/%s?h=i', $input->getOption('pattern'));
38
39 2
        $response = $client->request($uri);
40
41 2
        $output->writeln($response->getData()['message']);
42 2
    }
43
}
44