From 919cefbc525e9f1be46365142ce24d4240e3a2fa Mon Sep 17 00:00:00 2001 From: Eric Bottard Date: Thu, 7 Sep 2017 14:48:50 +0200 Subject: [PATCH] Document bean validation --- .../jline/JLineShellAutoConfiguration.java | 2 +- .../main/asciidoc/extending-spring-shell.adoc | 1 + .../src/main/asciidoc/using-spring-shell.adoc | 29 +++++++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/spring-shell-core/src/main/java/org/springframework/shell/jline/JLineShellAutoConfiguration.java b/spring-shell-core/src/main/java/org/springframework/shell/jline/JLineShellAutoConfiguration.java index e6d867c9..b34ebb1b 100644 --- a/spring-shell-core/src/main/java/org/springframework/shell/jline/JLineShellAutoConfiguration.java +++ b/spring-shell-core/src/main/java/org/springframework/shell/jline/JLineShellAutoConfiguration.java @@ -72,7 +72,7 @@ class JLineShellAutoConfiguration { @Autowired private Shell shell; - @Bean + @Bean(destroyMethod = "close") public Terminal terminal() { try { return TerminalBuilder.builder().build(); diff --git a/spring-shell-docs/src/main/asciidoc/extending-spring-shell.adoc b/spring-shell-docs/src/main/asciidoc/extending-spring-shell.adoc index cf962432..9e3087fd 100644 --- a/spring-shell-docs/src/main/asciidoc/extending-spring-shell.adoc +++ b/spring-shell-docs/src/main/asciidoc/extending-spring-shell.adoc @@ -1,6 +1,7 @@ [[extending-spring-shell]] == Extending Spring Shell +[[support-for-shell-1-and-jcommander]] === Support for Spring Shell 1 and JCommander diff --git a/spring-shell-docs/src/main/asciidoc/using-spring-shell.adoc b/spring-shell-docs/src/main/asciidoc/using-spring-shell.adoc index 16f5b863..63ff97c6 100644 --- a/spring-shell-docs/src/main/asciidoc/using-spring-shell.adoc +++ b/spring-shell-docs/src/main/asciidoc/using-spring-shell.adoc @@ -440,6 +440,35 @@ kbd:[Esc b] to move forward (_resp._ backward) one word at a time. TBD +=== Validating Command Arguments + +Spring Shell integrates with the http://beanvalidation.org/[Bean Validation API] to support +automatic and self documenting constraints on command parameters. + +Annotations found on command parameters as well as annotations at the method level will be +honored and trigger validation prior to the command executing. Given the following command: + +[source, java] +---- + @ShellMethod("Change password.") + public String changePassword(@Size(min = 8, max = 40) String password) { + return "Password successfully set to " + password; + } +---- + +You'll get this behavior, for free: +---- +shell:>change-password hello +The following constraints were not met: + --password string : size must be between 8 and 40 (You passed 'hello') +---- + +[NOTE] +.Applies to All Command Implementations +==== +It is important to note that bean validation applies to all command implementations, whether +they use the "standard" API or any other API, through the use of an adapter (see xref:support-for-shell-1-and-jcommander[Supporting Other APIs]) +==== [[dynamic-command-availability]] === Dynamic Command Availability