Skip to content
This repository was archived by the owner on Jun 25, 2025. It is now read-only.

Commit 9e8ca86

Browse files
hkulekcimmoreram
authored andcommitted
added print indices command
1 parent 81f8515 commit 9e8ca86

File tree

3 files changed

+111
-2
lines changed

3 files changed

+111
-2
lines changed

Command/PrintIndicesCommand.php

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Apisearch Bundle.
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*
9+
* Feel free to edit as you please, and have fun.
10+
*
11+
* @author Marc Morera <yuhu@mmoreram.com>
12+
*/
13+
14+
declare(strict_types=1);
15+
16+
namespace Apisearch\Command;
17+
18+
use Apisearch\Model\Index;
19+
use Symfony\Component\Console\Helper\Table;
20+
use Symfony\Component\Console\Input\InputArgument;
21+
use Symfony\Component\Console\Input\InputInterface;
22+
use Symfony\Component\Console\Output\OutputInterface;
23+
24+
/**
25+
* Class PrintIndicesCommand.
26+
*/
27+
class PrintIndicesCommand extends WithAppRepositoryBucketCommand
28+
{
29+
/**
30+
* Configures the current command.
31+
*/
32+
protected function configure()
33+
{
34+
$this
35+
->setName('apisearch:print-indices')
36+
->setDescription('Print all indices')
37+
->addArgument(
38+
'app-name',
39+
InputArgument::REQUIRED,
40+
'App name'
41+
);
42+
}
43+
44+
/**
45+
* Dispatch domain event.
46+
*
47+
* @param InputInterface $input
48+
* @param OutputInterface $output
49+
*
50+
* @return mixed|null
51+
*/
52+
protected function runCommand(InputInterface $input, OutputInterface $output)
53+
{
54+
$appName = $input->getArgument('app-name');
55+
$indices = $this
56+
->repositoryBucket
57+
->findRepository($appName)
58+
->getIndices();
59+
60+
$table = new Table($output);
61+
$table->setHeaders(['UUID', 'App Id', 'Is Ok?', 'Doc Count', 'Size']);
62+
/**
63+
* @var Index $index
64+
*/
65+
foreach ($indices as $index) {
66+
$table->addRow([
67+
$index->getUUID()->composeUUID(),
68+
$index->getAppUUID()->composeUUID(),
69+
$index->isOK() ? 'Yes' : 'No',
70+
$index->getDocCount(),
71+
$index->getSize(),
72+
]);
73+
}
74+
$table->render();
75+
}
76+
77+
/**
78+
* Dispatch domain event.
79+
*
80+
* @return string
81+
*/
82+
protected function getHeader(): string
83+
{
84+
return 'Print indices';
85+
}
86+
87+
/**
88+
* Get success message.
89+
*
90+
* @param InputInterface $input
91+
* @param mixed $result
92+
*
93+
* @return string
94+
*/
95+
protected function getSuccessMessage(
96+
InputInterface $input,
97+
$result
98+
): string {
99+
return '';
100+
}
101+
}

Command/PrintTokensCommand.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ protected function runCommand(InputInterface $input, OutputInterface $output)
5353
{
5454
$appName = $input->getArgument('app-name');
5555
$tokens = $this
56-
->repositoryBucket->findRepository($appName)
56+
->repositoryBucket
57+
->findRepository($appName)
5758
->getTokens();
5859

5960
$indexArray = $this

Resources/config/commands.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ services:
1010
tags:
1111
- { name: console.command }
1212

13+
apisearch.print_indices_command:
14+
class: Apisearch\Command\PrintIndicesCommand
15+
arguments:
16+
- "@apisearch.repository_bucket"
17+
tags:
18+
- { name: console.command }
19+
1320
apisearch.create_index_command:
1421
class: Apisearch\Command\CreateIndexCommand
1522
arguments:
@@ -73,4 +80,4 @@ services:
7380
arguments:
7481
- "@apisearch.app_repository_bucket"
7582
tags:
76-
- { name: console.command }
83+
- { name: console.command }

0 commit comments

Comments
 (0)