我使用的是Grails 2.5.0。
给出一个非常简单的Gant脚本,如下所示,我将它放在grails-app/scripts/TestScript.groovy中
includeTargets << grailsScript("_GrailsInit")
target(test: "The description of the script goes here!") {
ant.input(addProperty: 'name', message: "What's your name ? ", defaultvalue: 'anonymous')
println "Hello ${ant.antProject.properties.name}"
}
setDefaultTarget(test)如何让它与--non-interactive命令行标志一起工作?
我尝试通过grails test-script和grails test-script --non-interactive运行它,两个版本都会提示我输入用户信息。
根据documentation的说法,设置--non-interactive应该足以让它接受默认值(在本例中是匿名的),但事实并非如此。
发布于 2015-05-19 05:04:56
嗯,在看到this source code之后,我想出了这个解决方案:
includeTargets << grailsScript("_GrailsInit")
target(test: "The description of the script goes here!") {
def name = "anonymous"
if (isInteractive) {
ant.input(addProperty: 'name', message: "What's your name ? ", defaultvalue: name)
name = ant.antProject.properties.name
}
println "Hello ${name}"
}
setDefaultTarget(test)如果有更好的方法,我仍然乐于接受建议...
https://stackoverflow.com/questions/30311825
复制相似问题