Search

Dark theme | Light theme

June 14, 2012

Grails Goodness: Script Name Abbreviation

During Gr8Conf 2012 Europe I discovered Grails supports script name abbreviation. This means we don't have to type a complete script name, but only enough to make the script identifiable by Grails. It is inspired by Gradle's task name abbreviation feature. For example if we want to invoke the help script we only have to type the letter h. Or to invoke run-app we type rA. Notice we use uppercase characters for the letters after a hyphen in a script name. To invoke create-tag-lib we can type cTL.

If Grails cannot find a unique script name for the abbreviation we use we get a list of possible script names. We select the correct one to invoke the script. For example in the following output we see the options Grails shows when we type gen as a script name abbreviation:

$ grails gen
| Script 'Gen' not found, did you mean:
   1) GenerateAll
   2) GenerateViews
   3) GenerateController
   4) InstallDependency
   5) DependencyReport
> Please make a selection or enter Q to quit: 

This feature also works for script that we create ourselves or are added by plugins. For example if we create a script GrailsGoodness with the following content:

includeTargets << grailsScript("_GrailsInit")

target(main: "Demonstrate script name abbreviation") {
    println "Showing script name abbreviation in Grails"
}

setDefaultTarget(main)

On the command-line or at the Grails prompt we can now use gG as a script name abbreviation and Grails will invoke the GrailsGoodness script:

$ grails gG
| Environment set to development....
Showing script name abbreviation in Grails