spring-shell icon indicating copy to clipboard operation
spring-shell copied to clipboard

programmatic command registration: option name needs to match parameter name

Open georgmittendorfer opened this issue 10 months ago • 1 comments

Current behaviour:

Currently the following registration (assuming there is some pojo named command)

CommandRegistration.builder()
                .command("some-command")
                .withTarget().method(command, "add").and()
                .withOption().longNames("identity").and()
                .build();

matches the method

public String add(String identity) { ... }

but it would not match the method

public String add(String id) { ... }

That means that the option name needs to be equal to the parameter name but there is no reason for this as it is the only parameter. That is not very intuitive and it is not documented anywhere (at least I didn't find it).

Expected behaviour:

  • When target method only has one parameter it should match independent of the option name.
  • When target method only has one parameter it should even match given input without option name or there should be an error message that the option is missing (currently it simply passes null even if the option is required).
  • It should be documented somewhere what the requirements for option matching are.

georgmittendorfer avatar Apr 13 '24 10:04 georgmittendorfer

Thanks for comments. This type of registration was originally added to support registering annotated methods and its "magical" behaviour was somewhat baked inside logic discovering those methods. I think you're a first one asking how this behaves so point taken as It wasn't intentionally left hard to use.

jvalkeal avatar Apr 13 '24 12:04 jvalkeal