Allow non-String args in JOptCommandLinePropertySource
Prior to this commit, JOptCommandLinePropertySource prevented the possibility of non-String option arguments. This effectively prevents the use of JOpt's #ofType support (which allows specifying custom argument types). Now, non-String arguments are detected and converted to strings as necessary. JOpt's #ofType now works as expected. A test has been added to cover this case.
This commit is contained in:
committed by
Brian Clozel
parent
94ee763bc8
commit
dff48ad8dd
@@ -98,8 +98,7 @@ public class JOptCommandLinePropertySource extends CommandLinePropertySource<Opt
|
||||
List<?> argValues = this.source.valuesOf(name);
|
||||
List<String> stringArgValues = new ArrayList<String>();
|
||||
for (Object argValue : argValues) {
|
||||
Assert.isInstanceOf(String.class, argValue, "Argument values must be of type String");
|
||||
stringArgValues.add((String) argValue);
|
||||
stringArgValues.add(argValue instanceof String ? (String) argValue : argValue.toString());
|
||||
}
|
||||
if (stringArgValues.isEmpty()) {
|
||||
return (this.source.has(name) ? Collections.<String>emptyList() : null);
|
||||
|
||||
Reference in New Issue
Block a user