@Override public int compare(@Nullable Option o1, @Nullable Option o2) { return verifyNotNull(o1).getShortName().compareTo( verifyNotNull(o2).getShortName()); } });
void add(OptionParser e) { final Option option = e.getOption(); final String sn = option.getShortName(); checkDuplicateOption(sn); optionNames.add(sn); optionMap.put(sn, e); if (option.getLongName().isPresent()) { final String ln = option.getLongName().get(); checkDuplicateOption(ln); optionNames.add(ln); optionMap.put(ln, e); } if (buildingGroup) { groups.get(groups.size() - 1).add(option); } }
for (final Option opt : options) { final StringBuilder sb = new StringBuilder(); sb.append(" -").append(opt.getShortName()); if (opt.getLongName().isPresent()) { sb.append(",--").append(opt.getLongName().get());
for (final Option option : group) { final OptionParser exec = menu.optionMap.get(option .getShortName()); add(adapt(exec, shortPrefix, longPrefix)); newOptions.remove(exec);
/** * Tests whether the specified args will fail. * @param m The menu to use. * @param failingOptionName The name of the failing option. * @param causeType The cause of the error. * @param args The options to execute. */ public static void testFail(Menu m, String failingOptionName, CauseType causeType, String... args) { try { m.execute(args); } catch (final CliException e) { assertEquals(failingOptionName, e .getMenuOption().get().getShortName()); assertEquals(causeType, e .getCauseType()); return; } fail("No exception occured."); }
/** * Tests whether the specified args will fail. * @param m The menu to use. * @param failingOptionName The name of the failing option. * @param causeType The cause of the error. * @param rootCause The type of the throwable which is the root cause of the * failure. * @param args The options to execute. */ public static void testFail(Menu m, String failingOptionName, CauseType causeType, Class<? extends Throwable> rootCause, String... args) { try { m.execute(args); } catch (final CliException e) { assertEquals(failingOptionName, e.getMenuOption().get().getShortName()); assertEquals(causeType, e.getCauseType()); assertEquals(rootCause, e.getCause().getClass()); return; } fail(); }
assertFalse(Option.builder("A").build().getLongName().isPresent()); final Option o = Option.builder("A-T").longName("APPLE-TREE").build(); assertEquals("A-T", o.getShortName()); assertEquals("APPLE-TREE", o.getLongName().get());