为自定义grails脚本编写帮助

时间:2015-03-10 13:41:52

标签: grails groovy

我正在编写自定义grails脚本。我想要自定义帮助,选项等。

根据doc( http://grails.github.io/grails-doc/latest/guide/commandLine.html#creatingCustomScripts),我只需要这样做:

description( "Generates a controller that performs CRUD operations and the associated views" ) {
  usage "grails generate-all [DOMAIN CLASS]"
  flag name:'force', description:"Whether to overwrite existing files"
  argument name:'Domain Class', description:'The name of the domain class'
}

但是,当我将其添加到我的脚本中时,我得到:

Warning: Error caching created help for /server/scripts/ExecuteDBScript.groovy: No signature of method: ExecuteDBScript.description() is applicable for argument types: (java.lang.String, ExecuteDBScript$_run_closure1) values: [Generates a controller that performs CRUD operations and the associated views, ...]

我的脚本如下:

includeTargets << grailsScript("_GrailsInit")


description( "Generates a controller that performs CRUD operations and the associated views" ) {
    usage "grails generate-all [DOMAIN CLASS]"
    flag name:'force', description:"Whether to overwrite existing files"
    argument name:'Domain Class', description:'The name of the domain class'
}
/**
 * Script to execute the DB script.
 *
 */
target(main: "This script executes DB Script") {
...
}

有什么想法吗?

2 个答案:

答案 0 :(得分:1)

文档很差,但我找到了这个解决方案:

includeTargets << grailsScript("_GrailsBootstrap")

USAGE = """
    grails script-name [PARAM]

where
    PARAM       = Description
"""

target (default: "command description") {
    //...
}

答案 1 :(得分:0)

您的链接(http://grails.github.io/grails-doc/latest/guide/commandLine.html#creatingCustomScripts)是指最新版本的grails,一个非稳定版本(3.0.0.M2)。

您可能正在使用最新的稳定版本2.4.4,因此正确的文档位于此处:http://grails.github.io/grails-doc/2.4.4/ref/Command%20Line/create-script.html

相关问题