|
此版本仍在开发中,尚未被认为是稳定版。请使用最新稳定版 Spring Shell 4.0.1! |
选项验证
Spring Shell 通过与 Bean Validation API 集成,支持命令参数上的自动和自文档化约束。
注解应用于命令参数时会被认可,并在命令执行之前触发验证。 考虑以下命令:
@Command(name = "change-password", description = "Change password", group = "User Management",
help = "A command that changes the user password. Usage: change-password [-p | --password]=<password>")
public String changePassword(
@Option(shortName = 'p', longName = "password") @Size(min = 8, max = 40) String password) {
return "Password successfully set to " + password;
}
从前面的例子中,你可以免费获得以下行为:
$>change-password --password=hello
The following constraints were not met:
--password: size must be between 8 and 40
Error while executing command change-password: USAGE_ERROR