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