【问题标题】:Grails - generate-all to proceed without prompting for Overwrite?[y,n,a]Grails - generate-all 继续而不提示 Overwrite?[y,n,a]
【发布时间】:2015-03-13 11:58:53
【问题描述】:

每次我尝试构建 generate-all 命令时,它都会提示我 Overwrite?[y,n,a] 进行输入。有没有办法默认选择'y'。

编辑: 我是第一次设置框架,并且经常更改模型并生成要检查的视图和控制器。

更新:选择选项'a',它会自动覆盖所有文件,而不是每次都提示。

【问题讨论】:

  • 正如我在下面所说的,您应该能够传递--non-interactive,但在这些脚本中它被忽略了。幸运的是,它们现在在脚手架插件中,所以如果你在jira.grails.org/browse/GPSCAFFOLD 报告问题,我会修复这个问题并发布一个更新的插件。
  • 是的,正如您所说,它不起作用,但我阅读了文档。感谢您提供详细信息。

标签: grails grails-2.4


【解决方案1】:

如果你通过谷歌登陆这里。

新 grails (3.x) 具有 regenerate generated files 的“-force”选项

$ grails generate-all bookstore.Author                                                                               
Warning |                                                                                                            
Destination file grails-app\controllers\bookstore\AuthorController.groovy already exists, skipping...                
Warning |                                                                                                            
Destination file src\test\groovy\bookstore\AuthorControllerSpec.groovy already exists, skipping...                   
Warning |                                                                                                            
Destination file grails-app\views\author\edit.gsp already exists, skipping...                                        
Warning |                                                                                                            
Destination file grails-app\views\author\create.gsp already exists, skipping...                                      
Warning |                                                                                                            
Destination file grails-app\views\author\index.gsp already exists, skipping...                                       
Warning |                                                                                                            
Destination file grails-app\views\author\show.gsp already exists, skipping...                                        
|Scaffolding completed for grails-app\domain\bookstore\Author.groovy                                                 


$ grails generate-all -force bookstore.Author                                                                        
|Rendered template Controller.groovy to destination grails-app\controllers\bookstore\AuthorController.groovy         
|Rendered template Spec.groovy to destination src\test\groovy\bookstore\AuthorControllerSpec.groovy                  
|Rendered template edit.gsp to destination grails-app\views\author\edit.gsp                                          
|Rendered template create.gsp to destination grails-app\views\author\create.gsp                                      
|Rendered template index.gsp to destination grails-app\views\author\index.gsp                                        
|Rendered template show.gsp to destination grails-app\views\author\show.gsp                                          
|Scaffolding completed for grails-app\domain\bookstore\Author.groovy                                                 

【讨论】:

  • 在 Grails 版本:3.2.8 中命令是 $ grails generate-all bookstore.Author -force
【解决方案2】:

不,没有选项可以这样做,因为此提示是为了保护现有代码不被意外覆盖。

您能否详细说明您的需求和这样做的原因,以便任何人都可以为您提供替代方案?

【讨论】:

  • 您听说过--non-interactive 开关吗?它在此处的文档中进行了描述:grails.org/doc/latest/guide/commandLine.html 它专为这种情况而设计,当您希望脚本运行并且只接受默认值并假设答案是肯定的时。不幸的是,生成脚本不检查它的存在,但这是一个应该修复的错误。
  • 非常感谢您加入 Burt 的评论。
【解决方案3】:

在 Grails 版本中:3.2.8 命令是 $ grails generate-all bookstore.Author -force

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-05
    相关资源
    最近更新 更多