如何使用Groovy CliBuilder解析未命名的arg值?
我使用CliBuilder解析一些命名参数(h、t、c、n、s): 调用命令行看起来像:hl7benchmark-txxx-cyy-nzzz-saa:bbb 我需要在末尾添加一个可选属性,但我不希望它被命名,例如:如何使用Groovy CliBuilder解析未命名的arg值?,groovy,Groovy,我使用CliBuilder解析一些命名参数(h、t、c、n、s): 调用命令行看起来像:hl7benchmark-txxx-cyy-nzzz-saa:bbb 我需要在末尾添加一个可选属性,但我不希望它被命名,例如: hl7-benchmark -t xxx -c yyy -n zzz -s aaa:bbb final_value_without_name 在CliBuilder中可以这样做吗?我找不到任何这样的例子 谢谢 您只需将其作为命令行的“参数”部分: def test(args) {
hl7-benchmark -t xxx -c yyy -n zzz -s aaa:bbb final_value_without_name
在CliBuilder中可以这样做吗?我找不到任何这样的例子
谢谢 您只需将其作为命令行的“参数”部分:
def test(args) {
def cli = new CliBuilder(usage: 'hl7-benchmark -[t] type -[c] concurrency -[n] messages -[s] ip:port')
cli.with {
h longOpt: 'help', 'Show usage information'
t longOpt: 'type', args: 1, argName: 'type', 'mllp|soap'
c longOpt: 'concurrency', args: 1, argName: 'concurrency', 'number of processes sending messages'
n longOpt: 'messages', args: 1, argName: 'messages', 'number of messages to be send by each process'
s longOpt: 'ip:port', args: 2, argName: 'ip:port', 'server IP address:server port', valueSeparator: ':'
}
def options = cli.parse(args)
def otherArguments = options.arguments()
println options.t
println options.c
println options.n
println options.ss // http://www.kellyrob99.com/blog/2009/10/04/groovy-clibuilder-with-multiple-arguments/#hide
println otherArguments
}
test(['-t', 'xxx', '-c', 'yyy', '-n', 'zzz', '-s', 'aaa:bbb', 'final_value_without_name'])
上述情况表明:
xxx
yyy
zzz
[aaa, bbb]
[final_value_without_name]
如果希望在将参数放在选项之前时也能正确解析参数,可以将
stopAtNonOption
设置为false,就像在Awesome中一样,这非常有用。
xxx
yyy
zzz
[aaa, bbb]
[final_value_without_name]