protected function execute(InputInterface $input, OutputInterface $output)
{
$container = $this->getApplication()->getContainer();
$nodes = $container->get('nodes');
$format = $input->getOption('format');
if ('txt' === $format) {
if ($nodes) {
$isDetail = $input->getOption('detail');
$table = $this->getHelperSet()->get('table');
if ($isDetail) {
$table->setHeaders(array('name', 'host', 'port', 'username', 'key', 'roles'));
} else {
$table->setHeaders(array('name', 'roles'));
}
foreach ($nodes as $node) {
if ($isDetail) {
$table->addRow(array($node->getName(), $node->getHost(), $node->getPort(), $node->getUsername(), $node->getKey(), trim(implode(', ', $node->getReferenceRoles()))));
} else {
$table->addRow(array($node->getName(), trim(implode(', ', $node->getReferenceRoles()))));
}
}
$table->render($output);
} else {
$output->writeln('There are not any nodes.');
}
} else {
if ('json' === $format) {
$data = array();
if ($nodes) {
$isDetail = $input->getOption('detail');
foreach ($nodes as $node) {
if ($isDetail) {
$data[$node->getName()] = array('host' => $node->getHost(), 'port' => $node->getPort(), 'username' => $node->getUsername(), 'key' => $node->getKey(), 'roles' => $node->getReferenceRoles());
} else {
$data[$node->getName()] = array('roles' => $node->getReferenceRoles());
}
}
}
$output->writeln(json_encode($data));
} else {
throw new \InvalidArgumentException(sprintf('Unsupported format "%s".', $format));
}
}
}