我正在使用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应该足以使其接受默认值(在这种情况下为匿名),但事实并非如此。
最佳答案
好吧,看到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)
如果有更好的方法,我仍然愿意提出建议。
关于grails - 如何在自己的Grails脚本中使用非交互模式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30311825/