Вот рабочий пример моей проблемы:CliBuilder Аргументы Are Empty
def cli = new CliBuilder(usage: 'cli-test -d <argument>')
cli.with {
h(longOpt: 'help', 'usage information')
d(longOpt: 'do-something', required: true, args: 1, 'Do Something')
}
OptionAccessor options = cli.parse(args)
if(!options) {
return
}
// print usage if -h, --help, or no argument is given
if(options.h || options.arguments().isEmpty()) {
println options.arguments().size()
cli.usage()
return
} else if (options.d) {
println options.d
}
Когда я выполняю скрипт со следующим:
groovy cli-test.groovy -d hello
Я получаю этот выход:
0
usage: cli-test -d <argument>
-d,--do-something <arg> Do Something
-h,--help usage information
0
- это мой параметр printnn - длина аргументов. Я не могу получить какие-либо опции для работы, кроме h
. Я не уверен, что я делаю что-то неправильно.
'arguments' - это остаток вещей _after_ всех параметров. Так, например, при вызове 'groovy cli-test -d hello myfile yourfile'. то 'myfile, yourfile' являются' arguments'. – cfrick