如何在 grails gant 脚本中调用非默认目标

发布于 2024-09-06 17:15:41 字数 156 浏览 6 评论 0原文

我有一个甘特脚本 A 有两个目标

t1 - 默认目标 t2 - 另一个目标

即使当我运行

grails A t2

时,默认目标也会运行?如何运行非默认目标? 我已经尝试过 grails A --target='t2' 等,但不起作用。

I have a gant script A with two targets

t1 - default target
t2 - another target

Even when I run

grails A t2

the default target is run? How can I run the non-default target?
I have tried grails A --target='t2' etc. but doesn't work.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

抹茶夏天i‖ 2024-09-13 17:15:41

我不确定是否有正确的方法来做到这一点,但是您可以编写第二个脚本(“T2.groovy”)来加载这个脚本并将该目标设置为其默认值,例如

includeTargets << new File("path/to/YourScript")

setDefaultTarget("t2")

I'm not sure if there's a proper way to do it, but you can write a second script ("T2.groovy") that loads this one and sets that target as its default, e.g.

includeTargets << new File("path/to/YourScript")

setDefaultTarget("t2")
王权女流氓 2024-09-13 17:15:41

对 argsParsing 方法的一个调整是运行 argsMap 中的元素并迭代地依赖它们。因此,您可以将脚本称为:

grails myScript do-this do-that do-the-other

scriptName = 'myScriptName'    
includeTargets << grailsScript("_GrailsArgParsing")

snip

target(main: "Default Target") {
  depends(parseArguments)
  if(argsMap?.size() == 0) {
    depends(scriptError)
  }
  argsMap.each() {
    if (it.value) {
       println "${scriptName} building: ${it.value}"
       depends(it.value)
    }
    else {
       depends(scriptError)
    }
  }
}

snip

target(help: "Print a help message") {
   println "${scriptName}: possible targets are..."
   println "\thelp - print this help message" 
}   

target(scriptError: "Print an error and die") {
   println "${scriptName}: Please specify at least one target name"
   depends(help) 
   exit 1   
}

A tweak to argsParsing approach is to run through elements from the argsMap and iteratively depend on them. So you could call your script something like:

grails myScript do-this do-that do-the-other

scriptName = 'myScriptName'    
includeTargets << grailsScript("_GrailsArgParsing")

snip

target(main: "Default Target") {
  depends(parseArguments)
  if(argsMap?.size() == 0) {
    depends(scriptError)
  }
  argsMap.each() {
    if (it.value) {
       println "${scriptName} building: ${it.value}"
       depends(it.value)
    }
    else {
       depends(scriptError)
    }
  }
}

snip

target(help: "Print a help message") {
   println "${scriptName}: possible targets are..."
   println "\thelp - print this help message" 
}   

target(scriptError: "Print an error and die") {
   println "${scriptName}: Please specify at least one target name"
   depends(help) 
   exit 1   
}
世界等同你 2024-09-13 17:15:41

这是我采取的另一种方法

includeTargets << grailsScript("_GrailsArgParsing")

snip

target(main: "a script") { 
    if(!argsMap.target)
        throw new IllegalArgumentException("please specify target name with --target option")

   depends(argsMap.target)
}

setDefaultTarget(main)

您使用参数运行脚本。该参数是要运行的方法的名称:) 然后执行该方法。

This is another approach that I took

includeTargets << grailsScript("_GrailsArgParsing")

snip

target(main: "a script") { 
    if(!argsMap.target)
        throw new IllegalArgumentException("please specify target name with --target option")

   depends(argsMap.target)
}

setDefaultTarget(main)

You run the script with a parameter. That parameter is the name of the method to run :) That method then get's executed.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文