function main($filename, $dir, $params, $options)
{
    try {
        $setup = array();
        $configs = array();
        // bootstrap
        $bootstrap = new Bootstrap();
        if ($options[CMD_OPT_LIST_EXPORTER]) {
            $formatters = $bootstrap->getFormatters();
            // find the longest formatter name
            $len = max(array_map('strlen', array_keys($formatters))) + 1;
            echo "Supported exporter:\n";
            foreach ($formatters as $name => $class) {
                $formatter = $bootstrap->getFormatter($name);
                echo sprintf('- %-' . $len . "s %s\n", $name, $formatter->getTitle());
            }
            die(0);
        }
        if ('default' === $params[CMD_PARAM_EXPORT] && ($formatters = array_keys($bootstrap->getFormatters()))) {
            $params[CMD_PARAM_EXPORT] = $formatters[0];
        }
        // lookup config file export.json
        if (!$options[CMD_OPT_NO_AUTO_CONFIG] && !$params[CMD_PARAM_CONFIG]) {
            $config = getcwd() . DIRECTORY_SEPARATOR . 'export.json';
            if (is_readable($config)) {
                $params[CMD_PARAM_CONFIG] = $config;
            }
        }
        // check config file
        if ($config = $params[CMD_PARAM_CONFIG]) {
            if (!is_readable($config)) {
                echo sprintf("Can't read config file %s, using interactive mode.\n\n", $config);
            } else {
                if (null !== ($data = json_decode(file_get_contents($config), true))) {
                    echo sprintf("Using config file %s for parameters.\n\n", $config);
                    if (isset($data[CMD_PARAM_EXPORT])) {
                        $params[CMD_PARAM_EXPORT] = $data[CMD_PARAM_EXPORT];
                    }
                    if (isset($data[CMD_OPT_ZIP])) {
                        $options[CMD_OPT_ZIP] = (bool) $data[CMD_OPT_ZIP];
                    }
                    if (isset($data['dir'])) {
                        $dir = $data['dir'];
                    }
                    if (isset($data['params'])) {
                        $configs = $data['params'];
                    }
                } else {
                    echo sprintf("Ignoring invalid config file %s.\n\n", $config);
                }
            }
        }
        //get formatter after getting the parameter export either from command line or config file
        if (!($formatter = $bootstrap->getFormatter($params[CMD_PARAM_EXPORT]))) {
            echo sprintf('Unsupported exporter %s. Use --%s option to show all available exporter.', $params[CMD_PARAM_EXPORT], CMD_OPT_LIST_EXPORTER);
            die(1);
        }
        // parameters customization
        echo sprintf("Exporting %s as %s.\n\n", basename($filename), $formatter->getTitle());
        $setup = $formatter->getConfigurations();
        if (count($configs)) {
            mergeFormatter($setup, $configs);
        } else {
            $ask = false;
            askValue('Would you like to change the setup configuration before exporting', $ask);
            if ($ask) {
                setupFormatter($setup);
            }
        }
        // save export parameters
        if ($options[CMD_OPT_SAVE_CONFIG]) {
            file_put_contents('export.json', json_encode(array(CMD_PARAM_EXPORT => $params[CMD_PARAM_EXPORT], CMD_OPT_ZIP => $options[CMD_OPT_ZIP], 'dir' => $dir, 'params' => $setup)));
        }
        // start time
        $start = microtime(true);
        // parse the mwb file
        $formatter->setup($setup);
        $document = $bootstrap->export($formatter, $filename, $dir, $options[CMD_OPT_ZIP] ? 'zip' : 'file');
        // end time
        $end = microtime(true);
        if ($document) {
            echo sprintf("File exported to %s\n\n", $document->getWriter()->getStorage()->getResult());
            // show some information about used memory
            // show the time needed to parse the mwb file
            echo sprintf("Done in %0.3f second, %0.3f MB memory used.\n", $end - $start, memory_get_peak_usage(true) / 1024 / 1024);
            die(0);
        } else {
            echo "Export failed, may be there is no storage available.\n\n";
            die(1);
        }
    } catch (\Exception $e) {
        echo "Error:\n";
        echo $e->getMessage();
        die(1);
    }
}
 /**
  * Export with repository
  *
  * @param OutputInterface $output
  */
 public function exportWithRepository(OutputInterface $output)
 {
     $output->writeln(sprintf('Exporting "<info>%s</info>" schema', $this->getName()));
     $outputEntityDir = $this->getOutpuEntitytDir();
     $this->console->run(new ArrayInput(['command' => 'mkdir', 'path' => $outputEntityDir]));
     $bootstrap = new Bootstrap();
     // define a formatter and do configuration
     $formatter = $bootstrap->getFormatter($this->getOption('formatter'));
     $formatter->setup($this->getFormatterParams());
     // load document and export
     $output->writeln(sprintf('Create Entities'));
     $bootstrap->export($formatter, $this->getMwbFile(), $this->getOutpuModeltDir());
 }