From 2b7a9b15e64df16ba1ee6f793e43637ebc48b0f7 Mon Sep 17 00:00:00 2001 From: Johnny Marnell Date: Sun, 8 Nov 2020 12:22:41 -0500 Subject: [PATCH] Clarify how to achieve varying arity in docs Add examples of how to achieve, with existing functionality, a varying amount of parameter arity (and favor this verbage over "infinite", which, though technically true, could be misleading for evoking neding a very large amount of a parameter, instead of the normal usecase of a few of any amount). --- .../src/main/asciidoc/using-spring-shell.adoc | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) 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 d4de557c..747aab9c 100644 --- a/spring-shell-docs/src/main/asciidoc/using-spring-shell.adoc +++ b/spring-shell-docs/src/main/asciidoc/using-spring-shell.adoc @@ -348,9 +348,30 @@ shell:>add --numbers 1 --numbers 2 --numbers 3.3 ==== ===== -===== Infinite Arity +===== Varying Amount Arity -TO BE IMPLEMENTED +The above example demonstrates requiring a known, constant arity for a parameter, three in this case. Allowing any number of multiple values of a parameter can be achieved by leaving `arity` unspecified and using Spring's built-in comma separated value parsing for collections and/or arrays: +[source, java] +---- + @ShellMethod("Add a Varying Amount of Numbers.") + public double add(@ShellOption double[] numbers) { + return Arrays.stream(numbers).sum(); + } +---- + +The command may then be invoked with any amount of `numbers`: + +==== +[source] +---- +shell:>add 1,2,3.3 +6.3 +shell:>add --numbers 42 +42.0 +shell:>add --numbers 1,2,3.3,4,5 +15.3 +---- +==== ===== Special Handling of Boolean Parameters