I've recently started using Trollop, a clean and elegant command line option parser for all my small Ruby-based command line hacks. I found it was really easy to use, but getting started was difficult: despite good online documentation, there wasn't anything that showed how to incorporate Trollop into a complete script.
Q: How can I incorporate Trollop into my Ruby command-line program?
A: Here is a self-contained example.
The business with
if __FILE__ == $0
isn't specific to Trollop; that just means "run the following code if this file is executed as a script". This technique allows you use the file as a library module, separating the business logic from the command line parsing.With just that bit of code, you can now try all these things:
For more information, see http://trollop.rubyforge.org/