public SearchResult searchCommand(String name, String[] args) { CommandContainer command = commandMap.get(name); // Try to find the deepest available sub-command int index = 0; boolean subFound; if (args.length > 0) { do { subFound = false; Set<CommandContainer> childs = command.getChildCommands(); if (childs != null) { for (CommandContainer child : childs) { if (child.getName().equals(args[index])) { command = child; index++; subFound = true; break; } } } } while (index < args.length && subFound); } SearchResult result = new SearchResult(); result.container = command; result.deepness = index; return result; }