Coffeescript Cakefile - 命令行选项数组
是否可以将多个命令行参数传递给 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的:Cake 由 CoffeeScript 的 OptionParser 提供支持,它是从相同的 Ruby 实用程序移植的姓名。 可以多次使用一个选项来创建数组
如果您搜索 isList 的源代码,您会发现当(且仅当)正则表达式与长标志名称完全匹配时, 。简而言之:您只需在代码中添加一个字符即可。
*
使一切变得不同! :)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 regexis fully matched by the long flag name. In short: You just have to add one character to your code.
That
*
makes all the difference! :)