Hi all, my name is Hubert A. Klein Ikkink. Not a very common name, right? To make things easier I just picked the first letters of my firstname and surname and came up with haki. So there you have it, now I am also known as Mr. Haki or mrhaki for short. You can read more blog postings at www.mrhaki.com. I am a passionate Groovy and Java developer based in Tilburg, The Netherlands. My goal is to write clean, elegant, user-centered and high quality software. You can find me on Google+ and Twitter. Hubert is a DZone MVB and is not an employee of DZone and has posted 170 posts at DZone. You can read more from them at their website. View Full User Profile

Grails Goodness: Script Name Abbreviation

06.23.2012
| 3010 views |
  • submit to reddit

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

 

 

 

Published at DZone with permission of Hubert Klein Ikkink, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)