如何在您自己的Grails脚本中使用非交互模式?

时间:2015-05-18 20:00:15

标签: grails gant

我使用的是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-scriptgrails test-script --non-interactive运行它,两个版本都提示我输入用户。

根据https://cwiki.apache.org/confluence/display/KAFKA/Consumer+Group+Example,设置--non-interactive应该足以让它接受默认值(在这种情况下是匿名的),但它不是。

1 个答案:

答案 0 :(得分:0)

嗯,看到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)

如果有更好的方法,我仍然愿意接受建议......