我使用CliBuilder解析一些命名参数(h,t,c,n,s):
static main(args) {
// http://mrhaki.blogspot.com/2009/09/groovy-goodness-parsing-commandline.html
// http://docs.groovy-lang.org/latest/html/gapi/groovy/util/CliBuilder.html
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)
调用命令行如下所示:hl7-benchmark -t xxx -c yyy -n zzz -s aaa:bbb
我需要在末尾添加一个可选属性,但我不想将其命名为:
hl7-benchmark -t xxx -c yyy -n zzz -s aaa:bbb final_value_without_name
CliBuilder有可能吗? 我找不到任何示例。
谢谢!