spring-projects / spring-shell

Spring based shell
http://projects.spring.io/spring-shell/
Apache License 2.0
719 stars 395 forks source link

programmatic command registration: option name needs to match parameter name #1042

Open georgmittendorfer opened 4 months ago

georgmittendorfer commented 4 months ago

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:

jvalkeal commented 4 months ago

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.