use of org.apache.meecrowave.runner.cli.CliOption in project meecrowave by apache.
the class Cli method bind.
private static void bind(final Meecrowave.Builder builder, final CommandLine line, final List<Field> fields, final Object config) {
fields.forEach(f -> {
final CliOption opt = f.getAnnotation(CliOption.class);
final Optional<String> first = Stream.of(Stream.of(opt.name()), Stream.of(opt.alias())).flatMap(a -> a).filter(line::hasOption).findFirst();
if (first.isPresent()) {
final String name = first.get();
ofNullable(f.getType() == boolean.class ? ofNullable(line.getOptionValue(name)).map(Boolean::parseBoolean).orElse(true) : toValue(builder, name, line.getOptionValues(name), f.getType())).ifPresent(v -> {
if (!f.isAccessible()) {
f.setAccessible(true);
}
try {
f.set(config, v);
} catch (final IllegalAccessException e) {
throw new IllegalStateException(e);
}
});
}
});
}
Aggregations