Over a million developers have joined DZone.

Grails Goodness: Script Name Abbreviation

· Java Zone

Check out this 8-step guide to see how you can increase your productivity by skipping slow application redeploys and by implementing application profiling, as you code! Brought to you in partnership with ZeroTurnaround.

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

 

 

 

The Java Zone is brought to you in partnership with ZeroTurnaround. Check out this 8-step guide to see how you can increase your productivity by skipping slow application redeploys and by implementing application profiling, as you code!

Topics:

Published at DZone with permission of Hubert Klein Ikkink , DZone MVB .

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}