Document bean validation

This commit is contained in:
Eric Bottard
2017-09-07 14:48:50 +02:00
parent 3b0901af17
commit 919cefbc52
3 changed files with 31 additions and 1 deletions

View File

@@ -72,7 +72,7 @@ class JLineShellAutoConfiguration {
@Autowired
private Shell shell;
@Bean
@Bean(destroyMethod = "close")
public Terminal terminal() {
try {
return TerminalBuilder.builder().build();

View File

@@ -1,6 +1,7 @@
[[extending-spring-shell]]
== Extending Spring Shell
[[support-for-shell-1-and-jcommander]]
=== Support for Spring Shell 1 and JCommander

View File

@@ -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