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

标签 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运行它,并且两个版本都提示我输入用户信息。

根据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/

相关文章:

list - Grails在GSP( View )中更新列表,然后单击按钮提交

grails - 如果从脚手架模板调用,则找不到 Controller 方法

grails - 从grails项目执行gant脚本

grails - 将gant构建脚本转换为ant脚本

grails - Grails域类上缺少静态get方法

Grails文件上传-如何识别文件和/或内容类型?

logging - 为什么自动注入(inject)日志对象并不总是在 grails 中工作?

grails - Grails脚本调用我自己的Java类

grails - Grails war 中的Groovy旧版本

grails - 如何在 grails gant 脚本中调用非默认目标