protected function execute(InputInterface $input, OutputInterface $output)
 {
     $ti = microtime(true);
     $input_file = $input->getArgument('filename');
     $separator = $input->getOption('separator');
     $output->writeln(sprintf('<info>Exporting fields for "%s"</info>', $input_file));
     if (!file_exists($input_file)) {
         $output->writeln('<error>File not found.</error>');
         return;
     }
     $record = Tools::objectToDotNotationArray(json_decode(file_get_contents($input_file)));
     $output->writeln(implode($separator, array_keys($record)));
     $output->writeln(sprintf("<info>Finished exporting %d field names in %01.1f seconds</info>", count(array_keys($record)), microtime(true) - $ti));
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $ti = microtime(true);
     $entity_type = $input->getArgument('entity');
     $export_fields = explode(",", $input->getOption('fields'));
     $max_records = $input->getOption('max');
     $skip_records = $input->getOption('skip');
     $output_file = $input->getOption('outfile');
     $output->writeln(sprintf('<info>Exporting "%s"</info>', $entity_type));
     $out_dir = sprintf("%s/output/%s", $this->getApplication()->getAppPath(), $entity_type);
     if (!file_exists($out_dir)) {
         $output->writeln(sprintf('<error>Directory not found. [%s]</error>', $out_dir));
         return;
     }
     $writer = $output_file ? Writer::createFromPath($output_file, 'w') : $output;
     // process fields and build CSV headers
     foreach ($export_fields as $i => $field) {
         @(list($field, $field_as) = explode(" as ", $field));
         $headers[] = $field_as ?: $field;
         $export_fields[$i] = $field;
     }
     $this->write($writer, $headers);
     // process each json file file
     $idx = 0;
     foreach (glob($out_dir . '/*.json') as $file_name) {
         if ($idx++ < $skip_records) {
             continue;
         }
         $data = [];
         $record = Tools::objectToDotNotationArray(json_decode(file_get_contents($file_name)));
         foreach ($export_fields as $field) {
             $data[] = isset($record[$field]) ? $record[$field] : null;
         }
         $this->write($writer, $data);
         if ($idx == $max_records + $skip_records) {
             break;
         }
     }
     $output->writeln(sprintf("<info>Finished exporting %d \"%s\" records in %01.1f seconds</info>", $idx, $entity_type, microtime(true) - $ti));
 }