Groovy Multiple CliBuilder Arguments Without Commas

With Groovy CliBuilder it is possible to provide multiple arguments as described for example. here:

Example from the above link:

def cli = new CliBuilder(  
   usage: 'findClassesInJars.groovy -d <root_directories> -s <strings_to_search_for>',  
   header: '\nAvailable options (use -h for help):\n',  
   footer: '\nInformation provided via above options is used to generate printed string.\n')  
import org.apache.commons.cli.Option  
cli.with  
{  
   h(longOpt: 'help', 'Help', args: 0, required: false)  
   d(longOpt: 'directories', 'Two arguments, separated by a comma', args: Option.UNLIMITED_VALUES, valueSeparator: ',', required: true)  
   s(longOpt: 'strings', 'Strings (class names) to search for in JARs', args: Option.UNLIMITED_VALUES, valueSeparator: ',', required: true)  
}  

      

However, this means that the script needs to be called like this:

groovy script.groovy -d folder1,folder2,folder3

      

instead of the more usual (at least in the Unix world):

groovy script.groovy -d folder1 -d folder2 -d folder3

      

Is there a way to make it work like in the second example?

+3


source to share


1 answer


Yes, add the letter 's' to the argument name. This, by convention, will return an ArrayList, which you can execute to access all the values.



println "The first directory value: ${option.d}"
println "The directories as a list ${option.ds}"
options.ds.each{ it->
  println "directory: ${it}"
}

      

0


source







All Articles