このバージョンはまだ開発中であり、まだ安定しているとは見なされていません。最新の安定バージョンについては、Spring Shell 3.4.1 を使用してください! |
オプション検証
Spring Shell は Bean 検証 API (英語) と統合して、コマンドパラメーターの自動および自己ドキュメント化制約をサポートします。
Annotations found on command parameters are honored and trigger validation prior to the command executing. Consider the following command:
@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