Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed 'Config key is not set: host' error when executing status command #76

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

christianbader
Copy link

@christianbader christianbader commented Apr 2, 2024

Other suggestions are welcome 馃槃

Copy link
Contributor

@rliebi rliebi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @christianbader thank you :-) I have the feeling you are not on version 4.2.0 of Elastica bridge. However, if we change this, we should change it to something like this. What do you think?

The output would then look like this:

+------------------- Cluster ----+---------------+
| Key                            | Value         |
+--------------------------------+---------------+
| host                           |               |
| port                           |               |
| path                           |               |
| url                            |               |
| connections.0.host             | elasticsearch |
| connections.0.port             | 9200          |
| connections.0.transport_config | http_client   |
| roundRobin                     |               |
| retryOnConflict                | 0             |
| username                       |               |
| password                       |               |
| connectionStrategy             | Simple        |
+--------------------------------+---------------+

Comment on lines 45 to 53
{
$table = new Table($output);
$table
->setHeaders(['Host', 'Port', 'Version'])
->setHeaders(['Hosts', 'Version'])
->setRows([[
$this->esClient->getConfig('host'),
$this->esClient->getConfig('port'),
join(", ", $this->esClient->getConfig('hosts')),
$this->esClient->getVersion(),
]])
->setHeaderTitle('Cluster');
Copy link
Contributor

@rliebi rliebi Apr 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
{
$table = new Table($output);
$table
->setHeaders(['Host', 'Port', 'Version'])
->setHeaders(['Hosts', 'Version'])
->setRows([[
$this->esClient->getConfig('host'),
$this->esClient->getConfig('port'),
join(", ", $this->esClient->getConfig('hosts')),
$this->esClient->getVersion(),
]])
->setHeaderTitle('Cluster');
$config = [
...$this->esClient->getConfig(),
'version' => $this->esClient->getVersion(),
];
$table = new Table($this->io);
$table
->setHeaders(['Key', 'Value'])
->setRows(self::flattenConfig($config))
->setHeaderTitle('Cluster');
$table->render();
     private static function flattenConfig($config, $prefix = ''): array {
        $rows = [];
        foreach ($config as $key => $value) {
            if (is_array($value)) {
                foreach (self::flattenConfig($value, $prefix . $key . '.') as $row) {
                    $rows[] = $row;
                }
            } else {
                $rows[] = [$prefix . $key, $value];
            }
        }
        return $rows;
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants