// This needs to get called first, so that DirectiveFactory can report
// errors appropriately.
AppContext.init();
TaskType t = TaskType.TASK_MAP.get(args[0]);
if (t == null) {
// We did not find a task for this name. We should print help and quit.
// But because we are in the process of converting from the old Directive framework to
// the new Task framework, we may instead have to run oldMain. Therefore, don't
// System.exit; just return.
// TODO(dbentley): kill all Directives, print the relevant help, and exit instead
// of calling directiveMain().
try {
directiveMain(args);
} catch (IOException e) {
System.exit(1);
return;
}
return;
}
// Strip off the task name
// This mutates t.getOptions, and so has to be called before we create the injector.
Flags.parseOptions(t.getOptions(), ImmutableList.copyOf(args).subList(1, args.length));
Injector injector = Guice.createInjector(t, new MoeModule());
Task task = injector.getInstance(Task.class);
Task.Explanation result = task.executeAtTopLevel();
if (!Strings.isNullOrEmpty(result.message)) {