Groovy CliBuilder를 사용하여 명령 줄 옵션을 구문 분석하려고합니다. 짧은 옵션없이 여러 개의 긴 옵션을 사용하려고합니다. 나는 그것이 짧은 옵션 이름을 무시하고 단지 긴 옵션 이름을 사용할 때이 옵션에 "_"값을 여러 개를 사용할 수 있어야 끝내 문서에 따르면Groovy CliBuilder : 마지막 LongOpt 만 사용됩니다.
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: GString, "Type of processor (all, schema, beans, docs)"
_ longOpt: "dir-beans", args: 1, argName: "directory", type: GString, "Custom location for grails bean classes"
_ longOpt: "dir-orm", args: 1, argName: "directory", type: GString, "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의 문서에 따르면
Another example showing long options (partial emulation of arg processing for 'curl' command line):
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', args:1, 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
(마지막 하나가 발생). 내가 잘못된 것을하고 있습니까, 아니면이 문제를 해결할 수있는 방법이 있습니까?This example shows a common convention. When mixing short and long
이름을 짧은 이름은 종종 크기 일 개 문자입니다. 인수가있는 한 문자 옵션에는 옵션과 인수 사이에 공백이 필요하지 않습니다. -Ddebug = true. 예제에서는 짧은 옵션을 적용 할 수없는 경우 '_'사용을 보여줍니다.
또한 '_'이 여러 번 사용되었습니다. 다른 shortOpt 또는 longOpt가 반복되는 경우 지원되지만 이면 동작은 정의되지 않습니다.
http://groovy.codehaus.org/gapi/groovy/util/CliBuilder.html
나는이 "_"그것은 단지 목록의 마지막 하나를 받아 사용
감사합니다.
제대로 명령 줄 옵션을 구문 분석하지 않습니다 fyi,이 코드를 시도하면 두 번째 예외가 실패합니다. 구문 분석 함수 호출에서 긴 인수 사이에'='를 추가해야했습니다 :'parse "-x param --dir-beans = beans --dir-orm = orm".split ('')'. 나는 인수가 등호를 요구한다고 생각한다. – jmq
@jmquigley 그 문제가 없습니다. 아마도 내가 (1.8에있어) 몇 가지 오래된 오류가있을 수 있으므로 사용중인 버전을 묻기 시작 했어야했다. – jpertino