Using ‘@ShellOption’ argument, you can specify multiple keys for a single parameter.
Example
@ShellComponent(value = "Specify Multiple Named Parameter keys using @ShellOption")
public class CustomizeMultipleNamedKeysForSingleParameter {
@ShellMethod(value = "Commands to print Person Details", key = "print-person", prefix = "-")
public String printPersonDetails(String name, @ShellOption({"-emp-age", "-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();
}
}
As you see above snippet, I defined two shell options {"-emp-age", "-age"} for the parameter age. So you can use either -emp-age or -age while executing the command "print-person".
shell:>print-person -name "Krishna" -emp-age 45 --emp-city "Chennai" Hello Krishna!!!!. You are 45 years old and you are from Chennai shell:> shell:>print-person -name "Krishna" -age 45 --emp-city "Chennai" Hello Krishna!!!!. You are 45 years old and you are from Chennai
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