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).
This commit is contained in:
committed by
Janne Valkealahti
parent
763fef8e1b
commit
2b7a9b15e6
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user