protected function execute(InputInterface $input, OutputInterface $output)
{
$tags = $input->getOption('tag');
$tags = $this->convertTags($tags);
$mapping = ['InstanceId' => 'InstanceId', 'ImageId' => 'ImageId', 'State' => 'State.Name', 'SubnetId' => 'SubnetId', 'AZ' => 'Placement.AvailabilityZone', 'PublicIp' => 'PublicIpAddress', 'PrivateIp' => 'PrivateIpAddress', 'KeyName' => 'KeyName'];
// dynamically add current tags
foreach (array_keys($tags) as $tagName) {
$mapping[$tagName] = 'Tags[?Key==`' . $tagName . '`].Value | [0]';
}
foreach ($input->getOption('column') as $tagName) {
$mapping[$tagName] = 'Tags[?Key==`' . $tagName . '`].Value | [0]';
}
$repository = new Repository();
$instanceCollection = $repository->findEc2InstancesByTags($tags);
$rows = [];
foreach ($instanceCollection as $instance) {
/* @var $instance Instance */
$rows[] = $instance->extractData($mapping);
}
if (count($rows)) {
$table = new \Symfony\Component\Console\Helper\Table($output);
$table->setHeaders(array_keys(end($rows)))->setRows($rows);
$table->render();
} else {
$output->writeln('No matching instances found.');
}
}