首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在自己的Grails脚本中使用非交互模式?

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

Stack Overflow用户
提问于 2015-05-19 04:00:15
回答 1查看 322关注 0票数 0

我使用的是Grails 2.5.0。

给出一个非常简单的Gant脚本,如下所示,我将它放在grails-app/scripts/TestScript.groovy

代码语言:javascript
复制
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应该足以让它接受默认值(在本例中是匿名的),但事实并非如此。

EN

回答 1

Stack Overflow用户

发布于 2015-05-19 05:04:56

嗯,在看到this source code之后,我想出了这个解决方案:

代码语言:javascript
复制
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)

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30311825

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档