package com.bio4j.exporter;

import java.util.Scanner;

import org.apache.commons.cli.BasicParser;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.OptionBuilder;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;

public class Bio4jExporter {

	public static void main(String[] args) {
		// Gremlin gremlin = GremlinImpl.getInstance().getGremlin();
		Options options = generateOptions();
		BasicParser parser = new BasicParser();
		ExporterCore exporter = new ExporterCore();

		try {
			// parsing the command line arguments
			if (!parseCmdLineArgs(args, options, parser, exporter)) {
				return; // user asked for help, exporter stops
			}

			printBanner();
			Scanner scanIn = new Scanner(System.in);

			if (exporter.getFormat() == null) {
				System.out
				.print("Please state the desired output file format (Gexf/Graphml/GraphSON): ");
				String format = scanIn.nextLine();
				exporter.setFormat(format);
			}
			if (exporter.getSource() == null) {
				System.out.print("Please state input source adress: ");
				String source = scanIn.nextLine();
				exporter.setFormat(source);
			}
			System.out
			.print("Query (expressed in Gremlin Graph Querying Language): ");
			String query = scanIn.nextLine();
			exporter.setQuery(query);

			scanIn.close();

			System.out.print("Running query. . . ");
			exporter.runQuery();

			/* do exporter stuff */

		} catch (Exception exp) {
			System.out.println("Unexpected exception: " + exp.getMessage());
		}
	}

	/**
	 * @param args
	 * @param options
	 * @param parser
	 * @param exporter
	 * @throws ParseException
	 * @throws Exception
	 */
	private static boolean parseCmdLineArgs(String[] args, Options options,
			BasicParser parser, ExporterCore exporter) throws ParseException,
			Exception {

		CommandLine cmd = parser.parse(options, args);

		if (cmd.hasOption("help")) {
			// automatically generate the help statement
			HelpFormatter formatter = new HelpFormatter();
			formatter.printHelp("bio4j-exporter", options);
			return false;
		}

		if (cmd.hasOption("output-format")) {
			exporter.setFormat(cmd.getOptionValue("output-format"));
		}
		if (cmd.hasOption("limit")) {
			exporter.setLimit(cmd.getOptionValue("limit"));
		}
		if (cmd.hasOption("max-time")) {
			exporter.setMaxTime(cmd.getOptionValue("max-time"));
		}
		if (cmd.hasOption("stream")) {
			exporter.setStream(cmd.getOptionValue("stream"));
		}
		if (cmd.hasOption("source")) {
			exporter.setSource(cmd.getOptionValue("source"));
		}
		if (cmd.hasOption("query")) {
			exporter.setSource(cmd.getOptionValue("query"));
		}
		return true;
	}

	@SuppressWarnings("static-access")
	private static Options generateOptions() {

		Options options = new Options();

		options.addOption(OptionBuilder.withLongOpt("output-format")
				.withDescription("output file format (Gexf/Graphml/GraphSON)")
				.hasArg().withArgName("FORMAT").create());

		options.addOption(OptionBuilder.withLongOpt("limit")
				.withDescription("limit for results").hasArg()
				.withArgName("LIMIT").create());

		options.addOption(OptionBuilder.withLongOpt("max-time")
				.withDescription("maximum elapsed time").hasArg()
				.withArgName("TIME").create());

		options.addOption("s", "stream", true, "stream results ([yes]/[no])");

		options.addOption("h", "help", false, "print help statement");

		options.addOption("src", "source", true,
				"input source adress, supports local and remote addresses");

		options.addOption("q", "query", true,
				"query expressed in Gremlin Graph Querying Language");

		return options;
	}

	private static void printBanner() {
		String banner = " __     __         _____    __                                     __                \n"
				+ "|  |--.|__|.-----.|  |  |  |__| .-----..--.--..-----..-----..----.|  |_ .-----..----.\n"
				+ "|  _  ||  ||  _  ||__    | |  | |  -__||_   _||  _  ||  _  ||   _||   _||  -__||   _|\n"
				+ "|_____||__||_____|   |__|  |  | |_____||__.__||   __||_____||__|  |____||_____||__|  \n"
				+ "                          |___|               |__|                                   ";
		System.out.println(banner);
	}
}

@@ -862,16 +862,18 @@
 out%0A%09%09%09%09
+%09%09
 .print(%22
@@ -1210,16 +1210,18 @@
 tem.out%0A
+%09%09
 %09%09%09.prin
@@ -2616,38 +2616,37 @@
 %0A%09%09%09exporter.set
-Source
+Query
 (cmd.getOptionVa

Fix typo