Process given values is a parser

- Modify CommandParser to convert given option value if its type is defined
- This change makes option default value to behave same as given value
  what comes for the actual value in a CommandContext.
- Fixes #548
This commit is contained in:
Janne Valkealahti
2022-10-14 06:33:44 +01:00
parent df45b625c7
commit 3fe26025cd
3 changed files with 45 additions and 3 deletions

View File

@@ -323,6 +323,11 @@ public interface CommandParser {
List<String> subArgs = lr.subList(1, lr.size());
ConvertArgumentsHolder holder = convertArguments(o, subArgs);
Object value = holder.value;
if (conversionService != null && o.getType() != null && value != null) {
if (conversionService.canConvert(value.getClass(), o.getType().getRawClass())) {
value = conversionService.convert(value, o.getType().getRawClass());
}
}
Stream<ParserResult> unmapped = holder.unmapped.stream()
.map(um -> ParserResult.of(null, Arrays.asList(um), null, null));
Stream<ParserResult> res = Stream.of(ParserResult.of(o, subArgs, value, null));
@@ -341,7 +346,7 @@ public interface CommandParser {
defaultValueOptionsToCheck.remove(pr.option);
}
});
defaultValueOptionsToCheck.stream()
defaultValueOptionsToCheck.stream()
.filter(co -> co.getDefaultValue() != null)
.forEach(co -> {
Object value = co.getDefaultValue();