Coffeescript Cakefile - 命令行选项数组

发布于 2024-12-19 15:14:08 字数 531 浏览 1 评论 0原文

是否可以将多个命令行参数传递给 Cakefile 并捕获数组中的这些值?例如,这样的事情:

option '', '--compilation-level [LEVEL]', 'Description...'
task "build", "compile js", (options)->
    compilationLevels = options['compilation-level'] || ['DEFAULT']
    if compilationLevels.length >= 2
        console.log 'multiple compiles'
    else
        console.log 'just one compile'

然后用 cake --compilation-level ADVANCED_OPTIMIZATIONS --compilation-level SIMPLE_OPTIMIZATIONS build 运行它

如果这是不可能的,那么关于完成此操作的最佳方法的建议将是巨大的赞赏:)

Is it possible to pass multiple cmdline args to a Cakefile and capture those values in an array? For example something like this:

option '', '--compilation-level [LEVEL]', 'Description...'
task "build", "compile js", (options)->
    compilationLevels = options['compilation-level'] || ['DEFAULT']
    if compilationLevels.length >= 2
        console.log 'multiple compiles'
    else
        console.log 'just one compile'

Then run it w/ cake --compilation-level ADVANCED_OPTIMIZATIONS --compilation-level SIMPLE_OPTIMIZATIONS build

If this is not possible then suggestions on the most optimal way to accomplish this would be greatly appreciated :)

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

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

发布评论

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

评论(1

謌踐踏愛綪 2024-12-26 15:14:08

是的:Cake 由 CoffeeScript 的 OptionParser 提供支持,它是从相同的 Ruby 实用程序移植的姓名。 可以多次使用一个选项来创建数组

OPTIONAL   = /\[(\w+(\*?))\]/

如果您搜索 isList 的源代码,您会发现当(且仅当)正则表达式与长标志名称完全匹配时, 。简而言之:您只需在代码中添加一个字符即可。

option '', '--compilation-level [LEVEL*]', 'Description...'

* 使一切变得不同! :)

Yep: Cake is powered by CoffeeScript's OptionParser, which is ported from the Ruby utility of the same name. If you search the source for isList, you'll see that an option can be used multiple times to create an array if (and only if) the regex

OPTIONAL   = /\[(\w+(\*?))\]/

is fully matched by the long flag name. In short: You just have to add one character to your code.

option '', '--compilation-level [LEVEL*]', 'Description...'

That * makes all the difference! :)

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