如何在Thor中指定多个参数或参数?

时间:2012-05-02 05:42:07

标签: ruby command-line-interface command-line-arguments thor

my_gem你好name1 name2 name3给我一个

  

my_gem hello至少需要1个参数:my_gem hello name

我应该解析它们并用分隔符分隔参数吗?

e.g

  

my_gem hello name1,name2,name3,nameN

在文件中它看起来像

class MyCLI < Thor
  desc "hello NAMES", "say hello to names"

  def hello(names)
    say "hello #{names.split(',')}"
  end
end

或者无论如何都要这样做?

1 个答案:

答案 0 :(得分:14)

是的,还有另一种方法可以做到这一点。

require 'thor'
class TestApp < Thor
    desc "hello NAMES", "long desc"
    def hello(*names)
        say "hello #{names.join('; ')}"
    end
end

它可以像这样调用:

$ thor test_app:hello first second third
hello first; second; third
相关问题