Fix ShellOption with required
- Take 2 - Fix case with optional. - Fixes #436
This commit is contained in:
@@ -140,7 +140,7 @@ public class StandardMethodTargetRegistrar implements MethodTargetRegistrar, App
|
|||||||
&& !ObjectUtils.nullSafeEquals(so.defaultValue(), ShellOption.NULL)) {
|
&& !ObjectUtils.nullSafeEquals(so.defaultValue(), ShellOption.NULL)) {
|
||||||
optionSpec.defaultValue(so.defaultValue());
|
optionSpec.defaultValue(so.defaultValue());
|
||||||
}
|
}
|
||||||
else {
|
if (ObjectUtils.nullSafeEquals(so.defaultValue(), ShellOption.NONE)) {
|
||||||
optionSpec.required();
|
optionSpec.required();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -119,6 +119,29 @@ public class StandardMethodTargetRegistrarTests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testOptionOptionalWithAnnotation() {
|
||||||
|
applicationContext = new AnnotationConfigApplicationContext(Sample3.class);
|
||||||
|
registrar.setApplicationContext(applicationContext);
|
||||||
|
registrar.register(catalog);
|
||||||
|
Map<String, CommandRegistration> registrations = catalog.getRegistrations();
|
||||||
|
assertThat(registrations).hasSize(1);
|
||||||
|
|
||||||
|
assertThat(registrations.get("say-hello")).isNotNull();
|
||||||
|
assertThat(registrations.get("say-hello").getOptions()).hasSize(1);
|
||||||
|
assertThat(registrations.get("say-hello").getOptions().get(0).isRequired()).isFalse();
|
||||||
|
assertThat(registrations.get("say-hello").getOptions().get(0).getDefaultValue()).isNull();
|
||||||
|
}
|
||||||
|
|
||||||
|
@ShellComponent
|
||||||
|
public static class Sample3 {
|
||||||
|
|
||||||
|
@ShellMethod("some command")
|
||||||
|
public String sayHello(@ShellOption( defaultValue = ShellOption.NULL) String what) {
|
||||||
|
return "hello " + what;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAvailabilityIndicators() {
|
public void testAvailabilityIndicators() {
|
||||||
applicationContext = new AnnotationConfigApplicationContext(SampleWithAvailability.class);
|
applicationContext = new AnnotationConfigApplicationContext(SampleWithAvailability.class);
|
||||||
|
|||||||
Reference in New Issue
Block a user