Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How you do specify multiple arguments or parameters in Thor?

my_gem hello name1 name2 name3 give me a

my_gem hello requires at least 1 argument: my_gem hello name

Should I just parse them and separate the arguments with a delimeter?

e.g

my_gem hello name1,name2,name3,nameN

In the file it would look like

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

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

Or is there anyway to do this?

like image 437
poymode Avatar asked May 02 '12 05:05

poymode


1 Answers

Yes, there is another way of doing this.

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

And it can be called like this:

$ thor test_app:hello first second third
hello first; second; third
like image 165
Dr. Simon Harrer Avatar answered Nov 15 '22 23:11

Dr. Simon Harrer