How to use non-interactive mode in your own Grails scripts?

401 Views Asked by At

I'm using Grails 2.5.0.

Given a very simple Gant script like the following, which I put in 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)

How do I make it work with the --non-interactive command-line flag ?

I tried to run it through grails test-script and grails test-script --non-interactive and both versions prompt me for the user input.

According to the documentation, setting --non-interactive should suffice to make it accept the defaults (anonymous in this case), but it's not.

1

There are 1 best solutions below

0
On

Well, after seeing this source code I came up with this solution :

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)

I'm still open to suggestions if there is a better way...