- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 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: 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文档,当我希望它忽略短选项名称并仅使用长选项名称时,我应该能够对选项使用多个“_”值。根据 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
names, the short names are often one character in size. One character options with arguments don't require a space between the option and the argument, e.g. -Ddebug=true. The example also shows the use of '_' when no short option is applicable.
Also note that '_' was used multiple times. This is supported but if any other shortOpt or any longOpt is repeated, then the behavior is undefined.
http://groovy.codehaus.org/gapi/groovy/util/CliBuilder.html
当我使用“_”时,它只接受列表中的最后一个(最后一个遇到的)。我做错了什么还是有办法解决这个问题?
谢谢。
最佳答案
不知道你的意思它只接受最后一个。但这应该有效...
def cli = new CliBuilder().with {
x 'something', args:1
_ 'something', args:1, longOpt:'dir-beans'
_ 'something', args:1, 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'
关于Groovy CliBuilder : only last LongOpt is taken in account,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5798842/
我有一些库脚本:lib1.groovy: def a(){ } lib2.groovy: def b(){ } lib3.groovy: def c(){ } 并想在其他脚本中使用它们:配置文件: a
我有下面的 Groovy 脚本,我需要将它放在集中式 Groovy 库中,然后从 Ready API 项目中的任何脚本访问 Groovy 中提到的类 路径 : D:\GroovyLib\com\Lin
看完后this link ,我想尝试Groovy++,但我有一个担心; Groovy 的所有语法在 Groovy++ 中都有效吗? 例如,我可以在 Groovy 中执行此操作: def list =
我在 Spring-boot 应用程序中混合了 Groovy 和 Java。休息 Controller 和数据访问是用 Groovy 编写的。配置主要使用Java。 根据 logback 文档,如果类
我已阅读how to simply import a groovy file in another groovy script 我想在一个 groovy 文件中定义常用函数,并从其他 groovy 文
你知道,我也知道,只要只有一个是公共(public)的,就可以用 Java 实现。但是,在 Groovy 中可以这样做吗?如果是的话,在什么条件下? 最佳答案 Java 和 Groovy 之间在可以放
~/groovy % tree . ├── lib │ ├── GTemplate.class │ └── GTemplate.groovy └── Simple.groovy class
给定一个具有属性和构造函数的对象,我希望将构造函数参数复制到属性中,然后在构造函数中做一些额外的工作。 import groovy.transform.TupleConstructor @TupleC
我会提前道歉,我是 groovy 的新手。我的问题是我有 3 个执行不同功能的 groovy 脚本,我需要从我的主 groovy 脚本中调用它们,使用脚本 1 的输出作为脚本 2 的输入和脚本 2 的
我想在静态闭包中存储一些属性,然后在方法调用期间访问它们: class Person { static someMap = { key1: "value1", key2: "value2" } }
Groovy 是否有安全范围运算符? 例如,如果我有, [1,2,3][0..10] Groovy 会抛出一个 java.lang.IndexOutOfBoundsException: 有没有索引安全
在 Groovy 中使用 Maps/JsonBuilder 处理一些翻译/映射功能。 是否有可能(无需在 map 文字创建之外创建额外的代码).. 有条件地包含/排除某些键/值对?一些事情沿着以下路线
不知道我是否正确询问,但是我有类似以下内容: def x = 1 if (x == 1) { def answer = "yes" } println answer 我收到错误
我不明白 groovy 打字是如何工作的。在 wikipedia据说它具有很强的类型,但我可以在解释器上完美地做到这一点: 1 + '1' ==> 11 所以也许我很困惑,我不明白弱类型是什么,但我想
我对函数式编程概念非常陌生,正在观看 Neil Ford 在 youtube 中的演讲。 .在那里他谈到了一个计数器来演示一段代码而不使用全局状态(在 20:04)。来自 Java 世界,我很难理解这
我有两个问题。 我执行以下代码来查找 $ 的 ASCII 值: def a = "\$" def b = (int)a println b //prints 36 好吧,我对答案很满意。但是当我尝试像
只是想知道 时髦 像这样与默认值进行值匹配的方法? if(params.max != 10 && params.max != 20 && params.max != 30){ params.m
我最近正在读《行动中的格鲁夫》。在第7章中,它介绍了*。运算符(operator) 。当我运行有关此运算符的代码时,我会遇到一些错误。 class Invoice {
是否有易于阅读的方法或一些聪明的方法来制作 combination Groovy 中的元素?我知道 Iterable#combinations或 GroovyCollections#combinati
最近我下载了 Groovy-2.3.6 并尝试在 Linux 系统上安装它。我按照 http://groovy-lang.org/install.html 的说明进行操作.我设置了我的 GROOVY_
我是一名优秀的程序员,十分优秀!