@Test(expected = ParameterException.class) public void expand_fail() { JCommanderWrapper<Supplier<String>> commander = new JCommanderWrapper<>("PG", new ExpPrevent()); commander.parse("-aabb", "HELLO"); }
public Optional<T> parse(String... args) { String[] expandedArgs = expand(args); try { root.commander.parse(expandedArgs); } catch (ParameterException e) { Optional.ofNullable(findCommander()).ifPresent(e::setJCommander); throw e; } JCommander commander = findCommander(); @SuppressWarnings("unchecked") T cmd = (T) getActiveCommand(commander); if (cmd != null) { validate(commander, expandedArgs); return Optional.of(cmd); } return Optional.empty(); }
JCommanderWrapper implements CommandBuilder<T> { public Optional<T> parse(String... args) { String[] expandedArgs = expand(args); try { root.commander.parse(expandedArgs); } catch (ParameterException e) { Optional.ofNullable(findCommander()).ifPresent(e::setJCommander); throw e; } JCommander commander = findCommander(); @SuppressWarnings("unchecked") T cmd = (T) getActiveCommand(commander); if (cmd != null) { validate(commander, expandedArgs); return Optional.of(cmd); } return Optional.empty(); } }
JCommanderWrapper implements CommandBuilder<T> { public Optional<T> parse(String... args) { String[] expandedArgs = expand(args); try { root.commander.parse(expandedArgs); } catch (ParameterException e) { Optional.ofNullable(findCommander()).ifPresent(e::setJCommander); throw e; } JCommander commander = findCommander(); @SuppressWarnings("unchecked") T cmd = (T) getActiveCommand(commander); if (cmd != null) { validate(commander, expandedArgs); return Optional.of(cmd); } return Optional.empty(); } JCommanderWrapper(String programName, Object command); }
JCommanderWrapper implements CommandBuilder<T> { public Optional<T> parse(String... args) { String[] expandedArgs = expand(args); try { root.commander.parse(expandedArgs); } catch (ParameterException e) { Optional.ofNullable(findCommander()).ifPresent(e::setJCommander); throw e; } JCommander commander = findCommander(); @SuppressWarnings("unchecked") T cmd = (T) getActiveCommand(commander); if (cmd != null) { validate(commander, expandedArgs); return Optional.of(cmd); } return Optional.empty(); } JCommanderWrapper(String programName, Object command); @Override JCommanderWrapper<T> configure(Consumer<? super CommandBuilder<T>> configurator); @Override JCommanderWrapper<T> addCommand(T command); @Override JCommanderWrapper<T> addCommand(String name, T command); @Override JCommanderWrapper<T> addGroup(T command, Consumer<? super CommandBuilder<T>> configurator); @Override JCommanderWrapper<T> addGroup(String name, T command, Consumer<? super CommandBuilder<T>> configurator); Optional<T> parse(String... args); static void handle(ParameterException exception, Consumer<? super String> sink); }
JCommanderWrapper implements CommandBuilder<T> { public Optional<T> parse(String... args) { String[] expandedArgs = expand(args); try { root.commander.parse(expandedArgs); } catch (ParameterException e) { Optional.ofNullable(findCommander()).ifPresent(e::setJCommander); throw e; } JCommander commander = findCommander(); @SuppressWarnings("unchecked") T cmd = (T) getActiveCommand(commander); if (cmd != null) { validate(commander, expandedArgs); return Optional.of(cmd); } return Optional.empty(); } JCommanderWrapper(String programName, Object command); @Override JCommanderWrapper<T> configure(Consumer<? super CommandBuilder<T>> configurator); @Override JCommanderWrapper<T> addCommand(T command); @Override JCommanderWrapper<T> addCommand(String name, T command); @Override JCommanderWrapper<T> addGroup(T command, Consumer<? super CommandBuilder<T>> configurator); @Override JCommanderWrapper<T> addGroup(String name, T command, Consumer<? super CommandBuilder<T>> configurator); Optional<T> parse(String... args); static void handle(ParameterException exception, Consumer<? super String> sink);  }