【问题标题】:Writing help for a custom grails script编写自定义 grails 脚本的帮助
【发布时间】:2015-07-02 16:08:56
【问题描述】:

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

根据文档 ( 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") {
...
}

有什么想法吗?

【问题讨论】:

    标签: grails groovy


    【解决方案1】:

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

    includeTargets << grailsScript("_GrailsBootstrap")
    
    USAGE = """
        grails script-name [PARAM]
    
    where
        PARAM       = Description
    """
    
    target (default: "command description") {
        //...
    }
    

    【讨论】:

      【解决方案2】:

      您的链接 (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

      【讨论】:

        猜你喜欢
        • 2010-09-16
        • 1970-01-01
        • 1970-01-01
        • 2011-03-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-08-14
        相关资源
        最近更新 更多