Groovy CliBuilder:只考虑最后的LongOpt
我正在尝试使用groovy CliBuilder来解析命令行选项.我正在尝试使用多个长选项,而不是一个简短的选项.
我有以下处理器: def cli = new CliBuilder(usage: 'Generate.groovy [options]') cli.with { h longOpt: "help","Usage information" r longOpt: "root",args: 1,type: GString,"Root directory for code generation" x args: 1,"Type of processor (all,schema,beans,docs)" _ longOpt: "dir-beans",argName: "directory","Custom location for grails bean classes" _ longOpt: "dir-orm","Custom location for grails domain classes" } options = cli.parse(args) println "BEANS=${options.'dir-beans'}" println "ORM=${options.'dir-orm'}" if (options.h || options == null) { cli.usage() System.exit(0) } 根据groovy文档,当我希望它忽略短选项名称并仅使用长选项名称时,我应该能够为选项使用多个“_”值.根据groovy文档:
def cli = new CliBuilder(usage:'curl [options] <url>') cli._(longOpt:'basic','Use HTTP Basic Authentication') cli.d(longOpt:'data',args:1,argName:'data','HTTP POST data') cli.G(longOpt:'get','Send the -d data with a HTTP GET') cli.q('If used as the first parameter disables .curlrc') cli._(longOpt:'url',argName:'URL','Set URL to work with') Which has the following usage message: usage: curl [options] <url> --basic Use HTTP Basic Authentication -d,--data <data> HTTP POST data -G,--get Send the -d data with a HTTP GET -q If used as the first parameter disables .curlrc --url <URL> Set URL to work with
http://groovy.codehaus.org/gapi/groovy/util/CliBuilder.html 当我使用“_”时,它只接受列表中的最后一个(遇到最后一个).我做错了什么还是有办法解决这个问题? 谢谢. 解决方法
不确定你的意思它只接受最后一个.但这应该工作……
def cli = new CliBuilder().with { x 'something',args:1 _ 'something',longOpt:'dir-beans' _ 'something',longOpt:'dir-orm' parse "-x param --dir-beans beans --dir-orm orm".split(' ') } assert cli.x == 'param' assert cli.'dir-beans' == 'beans' assert cli.'dir-orm' == 'orm' (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |