Open danielburrell opened 3 years ago
https://docs.spring.io/spring-shell/docs/current-SNAPSHOT/reference/htmlsingle/#_customizing_arguments_conversion Doesn't this fits your requirement?
@ShellComponent
class ConversionCommands {
@ShellMethod("Shows conversion using Spring converter")
public String conversionExample(DomainObject object) {
return object.getClass();
}
}
class DomainObject {
private final String value;
DomainObject(String value) {
this.value = value;
}
public String toString() {
return value;
}
}
@Component
class CustomDomainConverter implements Converter<String, DomainObject> {
@Override
public DomainObject convert(String source) {
return new DomainObject(source);
}
}
docs.spring.io/spring-shell/docs/current-SNAPSHOT/reference/htmlsingle/#_customizing_arguments_conversion Doesn't this fits your requirement?
@ShellComponent class ConversionCommands { @ShellMethod("Shows conversion using Spring converter") public String conversionExample(DomainObject object) { return object.getClass(); } } class DomainObject { private final String value; DomainObject(String value) { this.value = value; } public String toString() { return value; } } @Component class CustomDomainConverter implements Converter<String, DomainObject> { @Override public DomainObject convert(String source) { return new DomainObject(source); } }
Not this. I know what he say because i meet the same question. I think that we hope to define the parameters in a pojo, and use it as normal parameters. For example, i defined a pojo
public class Pojo {
String name;
Integer age;
public String toString() {
return name + " " + age;
}
}
and put it into shell method
@ShellMethod
public void test(Pojo pojo) {
System.out.println(pojo);
}
then i could use it in commamd line like this:
spring-shell:-> test --name Tony --age 11
Tony 11
Are there any plans to support this?
@jvalkeal I would like to work on this request. This is my first contribution to Spring Shell.
It would be helpful if this would also work with jdk14 record
s.
@ShellCommandGroup("My Group")
class MyGroup {
record CommonArgs(
@ShellOption String a,
@ShellOption String b) {}
@ShellMethod
public void hello(@ShellOptions CommonArgs common) {
...
}
@ShellMethod
public void goodby(@ShellOptions CommonArgs common) {
...
}
}
Hi. Any updates on this?
Hi everyone
This feature very similar to @BeanParam in JAX-RS specification. You can get a lot of ideas from this annotation and its spec to implement new feature in spring framework.
I like contribute to this implementation too, if possible.
Given a complex command that has say 10 or more arguments, is it possible to annotate a pojo in the way method arguments would be annotated and pass a single pojo instead?
To illustrate
to this: