PrefixedJCommander extends JCommander { @Override public void addCommand(final String name, final Object object, final String... aliases) { super.addCommand(name, new Object(), aliases); final Iterator<Entry<Object, JCommander>> iter = childCommanders.entrySet().iterator(); Entry<Object, JCommander> last = null; while (iter.hasNext()) { last = iter.next(); } final PrefixedJCommander comm = new PrefixedJCommander(); comm.setProgramName(name, aliases); comm.setDefaultProvider(defaultProvider); comm.setAcceptUnknownOptions(allowUnknown); comm.setValidate(validate); if (object != null) { comm.addPrefixedObject(object); } if (last != null) { childCommanders.put(last.getKey(), comm); } } @SuppressWarnings("unchecked")  PrefixedJCommander(); @Override void addCommand(final String name, final Object object, final String... aliases); @Override void createDescriptions(); @Override void parse(final String... args); @Override void parseWithoutValidation(final String... args); @Override void setDefaultProvider(final IDefaultProvider defaultProvider); @Override void setAcceptUnknownOptions(final boolean allowUnknown); void setValidate(final boolean validate); List<Object> getPrefixedObjects(); void addPrefixedObject(final Object object); JCommanderTranslationMap getTranslationMap(); PrefixedJCommanderInitializer getInitializer(); void setInitializer(final PrefixedJCommanderInitializer initializer);  }
@Test public void testAddCommand() { final PrefixedJCommander prefixedJCommander = new PrefixedJCommander(); prefixedJCommander.addCommand("abc", (Object) "hello, world", "a"); prefixedJCommander.addCommand("def", (Object) "goodbye, world", "b"); prefixedJCommander.parse("abc"); Assert.assertEquals(prefixedJCommander.getParsedCommand(), "abc"); }