try {
try {
result = new GnuParser().parse(options, args);
} catch (ParseException e) {
System.out.println("Parse error " + e);
throw new TinyVMException(e.getMessage(), e);
}
if (result.hasOption("h"))
throw new TinyVMException("Help:");
if (result.getArgs().length == 1)
throw new TinyVMException(
"Must provide firmware and menu files");
if (result.getArgs().length > 2)
throw new TinyVMException("Too many files");
} catch (TinyVMException e) {
StringWriter writer = new StringWriter();
PrintWriter printWriter = new PrintWriter(writer);
printWriter.println(e.getMessage());
String commandName = System.getProperty("COMMAND_NAME",
"java lejos.pc.tools.NXJFlash");
String usage = commandName + " [options] [firmware menu]";
new HelpFormatter().printHelp(printWriter, 80, usage.toString(),
null, options, 0, 2, null);
throw new TinyVMException(writer.toString());
}
return result;
}