See below for an example script that prints "Hello World":
description "Example description", "grails hello-world"
The description
method is used to define the output seen by grails help
and to aid users of the script. The following is a more complete example of providing a description taken from the generate-all
command:
As you can see this description profiles usage instructions, a flag and an argument. This allows the command to be used as follows:
grails generate-all MyClass --force
Template Generation
Every Grails script implements the TemplateRenderer interface which makes it trivial to render templates to the users project workspace.
The following is an example of the command written in Groovy:
If a script is defined in a plugin or profile, the template(String)
method will search for the template in the application before using the template provided by your plugin or profile. This allows users of your plugin or profile to customize what gets generated.
templates("angular/**/*").each { Resource r ->
String path = r.URL.toString().replaceAll(/^.*?META-INF/, "src/main")
if (path.endsWith('/')) {
mkdir(path)
File to = new File(path)
SpringIOUtils.copy(r, to)
}
}
The "model"
Executing the model
method with a Class
/String
/File
/Resource
will return an instance of . The model contains several properties that can help you generate code.
Example:
In addition, an asMap
method is available to turn all of the properties into a map to pass to the method.