views:

296

answers:

1

How do I setup a Gem to have a binary command eg. "project newProject" that uses Thor's set of generator commands to create files etc.?

A good answer would describe how to layout the skeleton of a gem that that when run from the command line "project newProject" creates 1 file named "newProject.txt" in the directory it's run from.

I've seen that Rails 3 is using Thor to power it's generators, seems like a really good solution and i'd like to use a similar approach in non-Rails ruby gem i'm working on. Tried looking at the Rails 3 source but it's a bit labyrinthine hence the question.

A: 

in your gem project, you need to include a "bin" folder. this folder needs to include the ruby script that is your generator, without a file extension. if you are using something like jeweler, it will automatically scan the bin folder during packaging. when the gem is installed, the gem system will put the files from the bin folder into your ruby installation so that you can run them like you are wanting.

the bin files are just plain old ruby scripts, nothing special.

Derick Bailey