Source:
public static void main(String[] args) { int exitStatus = 1; Map<String, ModuleService> moduleServices = loadModules(ModuleService.class); try { Map<String, Object> argMap = parseArgs(args); setupLogger(argMap); if(argMap.containsKey("version")) { throw new ExitException( String.format("%1$s %2$s", Config.PACKAGE_DISPLAY_NAME, Config.PACKAGE_VERSION), 0 ); } List<String> others = (List<String>) argMap.get("__other__"); if (others.size() < 1) { throw new ExitException("Please provide module.", 0); } String module = others.remove(0); ModuleService moduleService = moduleServices.get(module); if (moduleService == null) { throw new IllegalArgumentException( String.format("No such '%1$s' module exists.", module) ); } moduleService.parseArguments(others); loadExtensions(moduleService, argMap); moduleService.run(); } catch(ExitException e) { if(e.isHelpPrint()) { List<String> modules = new ArrayList<>(moduleServices.keySet()); Collections.sort(modules); System.out.println( String.format( "usage: %s%sAvailable modules: %s%n\n", args[0] + " [options] ", e.getMessage(), StringUtils.join(modules, ", ") ) ); } else { System.out.println(e.getMessage()); } exitStatus = e.getExitCode(); } catch (Throwable t) { String message = t.getMessage() != null ? t.getMessage() : t.getClass().getName(); logger.error(message); logger.debug(message, t); } System.exit(exitStatus); }

Target:
public static void main(String[] args) { int exitStatus = 1; try { Map<String, Object> argMap = parseArgs(args); setupLogger(argMap); Map<String, ModuleService> moduleServices = loadModules(ModuleService.class); if(argMap.containsKey("help")) { argMap.put("__modules__", StringUtils.join(moduleServices.keySet(), ", ")); printHelpAndExit(argMap); } if(argMap.containsKey("version")) { System.out.println( String.format( "%1$s - %2$s (%3$s)", System.getProperty("org.ovirt.engine.exttool.core.packageDisplayName"), System.getProperty("org.ovirt.engine.exttool.core.packageVersion"), programName ) ); throw new ExitException(); } List<String> moduleOthers = (List<String>) argMap.get("__other__"); if (moduleOthers.size() < 1) { throw new ExitException("Please provide module.", 0); } String module = moduleOthers.remove(0); ModuleService moduleService = moduleServices.get(module); if (moduleService == null) { throw new IllegalArgumentException( String.format("No such '%1$s' module exists.", module) ); } loadExtensions(moduleService, argMap); moduleService.parseArguments(moduleOthers, moduleService.getName()); if(moduleService.doHelp()) { printHelpAndExit(moduleService.getArguments()); } List<String> actionOthers = (List<String>)moduleService.getArguments().get("__other__"); String action = actionOthers.remove(0); moduleService.parseArguments(actionOthers, action); if(moduleService.doHelp()) { printHelpAndExit(moduleService.getArguments()); } moduleService.run(action); } catch(ExitException e) { if(e.getMessage() != null) { System.out.println(e.getMessage()); } exitStatus = e.getExitCode(); } catch (Throwable t) { String message = t.getMessage() != null ? t.getMessage() : t.getClass().getName(); logger.error(message); logger.debug(message, t); t.printStackTrace(); } System.exit(exitStatus); }