if (args.length < 1) {
System.err.println("Usage: moe <directive>");
System.exit(1);
}
Directive d = DirectiveFactory.makeDirective(args[0]);
if (d == null) {
// DirectiveFactory.makeDirective has failed and reported the error.
System.exit(1);
}
MoeOptions flags = d.getFlags();
CmdLineParser parser = new CmdLineParser(flags);
boolean parseError = false;
try {
List<String> nextArgs = Lists.newArrayList(args);
nextArgs.remove(0); // Remove the directive.
parser.parseArgument(
processArgs(nextArgs).toArray(new String[] {}));
} catch (CmdLineException e) {
logger.log(Level.SEVERE, "Failure", e);
parseError = true;
}
if (flags.shouldDisplayHelp() || parseError) {
parser.printUsage(System.err);
System.exit(parseError ? 1 : 0);
}
try {
int result = d.perform();
Ui.Task terminateTask = AppContext.RUN.ui.pushTask(
Ui.MOE_TERMINATION_TASK_NAME, "Final clean-up");
AppContext.RUN.fileSystem.cleanUpTempDirs();
AppContext.RUN.ui.popTask(terminateTask, "");
System.exit(result);