@Test public void testConvert() throws ArgumentParserException { ArgumentImpl arg = new ArgumentImpl(config_, "--foo"); assertEquals("hello", arg.convert(null, "hello")); arg.choices("world"); try { ArgumentParserImpl ap = new ArgumentParserImpl(config_); arg.convert(ap, "hello"); fail(); } catch(ArgumentParserException e) { assertEquals("argument --foo: invalid choice: 'hello' (choose from {world})", e.getMessage()); } }
public Object convert(ArgumentParserImpl parser, String value) throws ArgumentParserException { Object obj = type_.convert(parser, this, value); if (choice_ != null && !choice_.contains(obj)) { throw new ArgumentParserException(String.format( TextHelper.LOCALE_ROOT, localize("invalidChoiceError"), value, choice_.textualFormat()), parser, this); } return obj; }
ArgumentImpl implements Argument { public Object convert(ArgumentParserImpl parser, String value) throws ArgumentParserException { Object obj = type_.convert(parser, this, value); if (choice_ != null && !choice_.contains(obj)) { throw new ArgumentParserException(String.format( TextHelper.LOCALE_ROOT, localize("invalidChoiceError"), value, choice_.textualFormat()), parser, this); } return obj; } }
ArgumentImpl implements Argument { public Object convert(ArgumentParserImpl parser, String value) throws ArgumentParserException { Object obj = type_.convert(parser, this, value); if (choice_ != null && !choice_.contains(obj)) { throw new ArgumentParserException(String.format( TextHelper.LOCALE_ROOT, localize("invalidChoiceError"), value, choice_.textualFormat()), parser, this); } return obj; } ArgumentImpl(ArgumentParserConfigurationImpl config,
            String... nameOrFlags);   ArgumentImpl(ArgumentParserConfigurationImpl config,
            ArgumentGroupImpl argumentGroup, String... nameOrFlags); }
ArgumentImpl implements Argument { public Object convert(ArgumentParserImpl parser, String value) throws ArgumentParserException { Object obj = type_.convert(parser, this, value); if (choice_ != null && !choice_.contains(obj)) { throw new ArgumentParserException(String.format( TextHelper.LOCALE_ROOT, localize("invalidChoiceError"), value, choice_.textualFormat()), parser, this); } return obj; } ArgumentImpl(ArgumentParserConfigurationImpl config,
            String... nameOrFlags);   ArgumentImpl(ArgumentParserConfigurationImpl config,
            ArgumentGroupImpl argumentGroup, String... nameOrFlags); @Override String textualName(); void printHelp(PrintWriter writer, boolean defaultHelp,
            TextWidthCounter textWidthCounter, int width); Object convert(ArgumentParserImpl parser, String value); @Override ArgumentImpl nargs(int n); @Override ArgumentImpl nargs(String n); @Override ArgumentImpl setConst(Object value); @Override ArgumentImpl setConst(E... values); @Override ArgumentImpl setDefault(Object value); @Override ArgumentImpl setDefault(E... values); @Override ArgumentImpl setDefault(FeatureControl ctrl); @Override ArgumentImpl type(Class<T> type); @Override ArgumentImpl type(ArgumentType<T> type); @Override ArgumentImpl required(boolean required); @Override ArgumentImpl action(ArgumentAction action); @Override ArgumentImpl choices(ArgumentChoice choice); @Override ArgumentImpl choices(Collection<E> values); @Override ArgumentImpl choices(E... values); @Override ArgumentImpl dest(String dest); @Override ArgumentImpl metavar(String... metavar); @Override ArgumentImpl help(String help); @Override ArgumentImpl help(FeatureControl ctrl); void run(ArgumentParserImpl parser, Map<String, Object> res,
            String flag, Object value); @Override String getDest(); @Override Object getConst(); @Override Object getDefault(); @Override FeatureControl getDefaultControl(); @Override FeatureControl getHelpControl(); String getName(); boolean isRequired(); String[] getMetavar(); ArgumentAction getAction(); String getHelp(); }
ArgumentImpl implements Argument { public Object convert(ArgumentParserImpl parser, String value) throws ArgumentParserException { Object obj = type_.convert(parser, this, value); if (choice_ != null && !choice_.contains(obj)) { throw new ArgumentParserException(String.format( TextHelper.LOCALE_ROOT, localize("invalidChoiceError"), value, choice_.textualFormat()), parser, this); } return obj; } ArgumentImpl(ArgumentParserConfigurationImpl config,
            String... nameOrFlags);   ArgumentImpl(ArgumentParserConfigurationImpl config,
            ArgumentGroupImpl argumentGroup, String... nameOrFlags); @Override String textualName(); void printHelp(PrintWriter writer, boolean defaultHelp,
            TextWidthCounter textWidthCounter, int width); Object convert(ArgumentParserImpl parser, String value); @Override ArgumentImpl nargs(int n); @Override ArgumentImpl nargs(String n); @Override ArgumentImpl setConst(Object value); @Override ArgumentImpl setConst(E... values); @Override ArgumentImpl setDefault(Object value); @Override ArgumentImpl setDefault(E... values); @Override ArgumentImpl setDefault(FeatureControl ctrl); @Override ArgumentImpl type(Class<T> type); @Override ArgumentImpl type(ArgumentType<T> type); @Override ArgumentImpl required(boolean required); @Override ArgumentImpl action(ArgumentAction action); @Override ArgumentImpl choices(ArgumentChoice choice); @Override ArgumentImpl choices(Collection<E> values); @Override ArgumentImpl choices(E... values); @Override ArgumentImpl dest(String dest); @Override ArgumentImpl metavar(String... metavar); @Override ArgumentImpl help(String help); @Override ArgumentImpl help(FeatureControl ctrl); void run(ArgumentParserImpl parser, Map<String, Object> res,
            String flag, Object value); @Override String getDest(); @Override Object getConst(); @Override Object getDefault(); @Override FeatureControl getDefaultControl(); @Override FeatureControl getHelpControl(); String getName(); boolean isRequired(); String[] getMetavar(); ArgumentAction getAction(); String getHelp();  }