I am trying to write a spring shell app and pass some var args. Basicaly I want to pass
fetch FA-207542 FA-207984 FA-211258 FA-202298
Documentation here is still TBD
@ShellMethod(value = "fetches all pic related data for processing")
fun fetch(vararg tickets: String) {
println("number of tickets is ${tickets.size}")
}
results
shell:>fetch FA-207542 FA-207984 FA-211258 FA-202298
number of tickets is 1
I've tried using a StringArray
and I get an error:
fun fetch(tickets: StringArray) {
println("number of tickets is ${tickets.size()}")
}
error:
shell:>fetch FA-207542 FA-207984 FA-211258 FA-202298
Parameter specified as non-null is null: method FetchCommand.fetch, parameter tickets
Details of the error have been omitted. You can use the stacktrace command to print the full stacktrace.
With java (sry), I got this working:
@ShellComponent
public class MyCommands {
@ShellMethod
public String fetch(String... tickets) {
return String.format("Number of tickets is %d.", tickets.length);
}
}
then:
shell:>fetch --tickets FA-207542 FA-207984 FA-211258 FA-202298
Number of tickets is 4.
shell:>
Same results achieved with: @ShellCommand(arity = -1)
resp. arity = Integer.MAX_VALUE
.#