【问题标题】:How to use non-interactive mode in your own Grails scripts?如何在自己的 Grails 脚本中使用非交互模式?
【发布时间】:2015-05-18 20:00:14
【问题描述】:

我正在使用 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 应该足以使其接受默认值(在这种情况下为匿名),但事实并非如此。

【问题讨论】:

    标签: grails gant


    【解决方案1】:

    好吧,在看到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)
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-12
      • 2012-02-02
      • 1970-01-01
      • 1970-01-01
      • 2014-07-16
      • 1970-01-01
      相关资源
      最近更新 更多