John Smith
John Smith

Reputation: 6269

Command Line hash input

I have a generator class that I can run like this:

rails g shopping_template --attributes=email:hello

It recognizes email as input. But when I want to add several attributes its not working, it only recognizes email:

rails g shopping_template --attributes=email:hello,name:hans,house:big

Ho do I have to change --attributes=email:hello,name:hans,house:big so that its recognized correctly as a hash?

Here's the code from the class:

class_option :attributes,
             type: :hash,
             default: {}

Upvotes: 1

Views: 84

Answers (1)

Raj
Raj

Reputation: 22956

Check the Thor document. This is the correct way to pass a hash:

--option=name:string age:integer

So for your example, it would be:

--attributes=email:hello name:hans house:big

Upvotes: 1

Related Questions