In my previous post, I explained how to customized the prefix while calling named parameters.
We can even customize named parameter keys using '@ShellOption' argument.
Example
@ShellComponent(value = "Customize Named Parameter keys using @ShellOption")
public class CustomizeNamedParamKeys {
@ShellMethod(value = "Commands to print Employee Details", key = "print-employee", prefix = "-")
public String printEmployeeDetails(String name, @ShellOption("emp-age") int age,
@ShellOption("--emp-city") String city) {
StringBuilder builder = new StringBuilder();
builder.append("Hello ").append(name).append("!!!!").append(". You are ").append(age)
.append(" years old and you are from ").append(city);
return builder.toString();
}
}
For the above example, the possible parameter keys will be -name, emp-age and –emp-city.
shell:>print-employee -name "Krishna" emp-age 23 --emp-city "Hyderabad" Hello Krishna!!!!. You are 23 years old and you are from Hyderabad
You can download complete application from this link.
https://github.com/harikrishna553/springboot/tree/master/shell/hello-world
Previous Next Home
No comments:
Post a Comment