public static void main(String[] args) {
		CommandLine cmd = createOptions(args);

		GeneratorError result = GeneratorError.NO_ERROR;
		try {
			//Build the output name, by default ./output
			String directory = cmd.getOptionValue("output", "./");
			if (!directory.endsWith(File.separator))
				directory += File.separator;
			String filename = cmd.getOptionValue("name", "output");
			String output=directory+filename;

			//Get the JSON from file if given, or get it from the standard input.
			String jsonText=null;
			if (!cmd.hasOption("input"))
			{
				// Initializes the input with the standard input
				jsonText = IOUtils.toString(System.in, "UTF-8");
			}
			else // read the file
			{
				FileInputStream inputStream = new FileInputStream(cmd.getOptionValue("input"));
				try {
					jsonText = IOUtils.toString(inputStream);
				} finally {
					inputStream.close();
				}
			}

			//Build the report object
			Report report = new Report(jsonText,cmd.getOptionValue("template"),output);

			//Generate the document
			if (cmd.hasOption("all"))
			{
				new AllGenerator(report).generate();
			}
			else
			{
				if (cmd.hasOption("html"))
					new HTMLGenerator(report).generate();
				if (cmd.hasOption("pdf"))
					new PDFGenerator(report).generate();
				if (cmd.hasOption("doc"))
					new DocGenerator(report).generate();
			}
			
		} catch (IOException e) {
			System.err.println("Error: "+e.getMessage());
			System.exit(GeneratorError.IO_ERROR.getCode());
		} catch (GeneratorException e) {
			System.err.println("Error: "+e.getMessage());
			System.exit(e.getError().getCode());
		}
		System.exit(result.getCode());
	}