如何创建用于代码生成的 CLI 脚本,就像 "grails create-controller" 所做的那样

How to create a CLI script for code generation, like what "grails create-controller" does

我想创建一个命令行工具来生成一些 java 源代码...例如,控制器 class、服务 class 和 DTO class.我一直试图找到 CreateController.groovy 的脚本(来自 grails),但我没有找到那个脚本。任何帮助将非常感激。我想这可能是用 Gant 完成的?

I've been trying to find the scripts for CreateController.groovy (from grails), but I've had no luck finding that script.

您没有指明您想使用哪个版本的 Grails,这可能是相关的。对于最新版本的 Grails,没有 CreateController.groovycreate-controller 命令定义在 https://github.com/grails/grails-profile-repository/blob/master/profiles/web/commands/create-controller.yml.

I think it might be done with Gant?

从 Grails 2 开始就没有了。如果您使用的是 Grails 1 或 2,那么 Gant 脚本可能就是您要找的东西。对于 Grails 2.5.6,命令定义在 https://github.com/grails/grails-core/blob/bd7cc10e17d34f20cedce979724f0e3bacd4cdb4/grails-scripts/src/main/scripts/CreateController.groovy.