【问题标题】:rake command parsing options after --rake 命令解析选项后 --
【发布时间】:2015-01-22 14:59:20
【问题描述】:

根据“How to pass command line arguments to a rake task”,我认为以下方法可行。

$ rake command -- other options

但是调用失败并出现invalid option 错误。答案是:

注意--,这是绕过标准 rake 参数所必需的。

这对我不起作用。有解决办法吗?

【问题讨论】:

    标签: ruby bash rake


    【解决方案1】:

    结果证明使用key=value 语法有效。所以设置选项使用这个。

    $ rake command option= key=value
    

    这会在命令中为您提供参数。

    args = ARGV.grep(/=/).map{ |s| [ *s.split(/=/), true ][0, 2] }.to_h
    # => { "option" => true, "key" => "value" }
    

    或者更简单的键。

    args = ARGV.flat_map{ |s| s[/(\w+)=/, 1] }.compact
    # => [ "option", "key" ]
    

    【讨论】:

      猜你喜欢
      • 2015-02-28
      • 1970-01-01
      • 2012-08-18
      • 1970-01-01
      • 2013-05-16
      • 2012-01-06
      • 1970-01-01
      • 2019-11-27
      • 2017-08-31
      相关资源
      最近更新 更多