Add better support for modified option names

- Longnames in a command option if modified via
  name modifier didn't provide enough backmapping
  info for command execution experience being accurate.
- Add new getLongNamesModified() into CommandOption
  which is populated if name modifier is used.
- Add more hints in CommandExecution for modified
  option names.
- This should bring annotation
  and programmatic commands up to date.
- Backport #777
- Fixes #782
This commit is contained in:
Janne Valkealahti
2023-06-19 12:30:29 +01:00
parent 21fc4551e6
commit eaa363b34c
7 changed files with 68 additions and 16 deletions

View File

@@ -28,12 +28,13 @@ public class OptionNamingCommands {
public static class LegacyAnnotation extends BaseE2ECommands {
@ShellMethod(key = LEGACY_ANNO + "option-naming-1", group = GROUP)
public void testOptionNaming1Annotation(
public String testOptionNaming1Annotation(
@ShellOption("from_snake") String snake,
@ShellOption("fromCamel") String camel,
@ShellOption("from-kebab") String kebab,
@ShellOption("FromPascal") String pascal
) {
return String.format("snake='%s' camel='%s' kebab='%s' pascal='%s' ", snake, camel, kebab, pascal);
}
}
@@ -65,10 +66,16 @@ public class OptionNamingCommands {
.withOption()
.longNames("arg1")
.nameModifier(name -> "x" + name)
.required()
// .required()
.and()
.withTarget()
.consumer(ctx -> {})
.function(ctx -> {
String snake = ctx.getOptionValue("from_snake");
String camel = ctx.getOptionValue("fromCamel");
String kebab = ctx.getOptionValue("from-kebab");
String pascal = ctx.getOptionValue("FromPascal");
return String.format("snake='%s' camel='%s' kebab='%s' pascal='%s' ", snake, camel, kebab, pascal);
})
.and()
.build();
}