Command Line Options Parsing in Ruby
One of the most common ways how to control a command line application is to use options, e.g. almost every command line application would understand -h
or --help
or /?
(common in the MS-DOS world) as a request to show some instruction.
Ruby (but also other programming languages such as Java) has a basic support for accessing command line arguments, so there is a space for libraries that make reading options easier such as Trollop, Optiflag or Choice.
Update: Actually not so true for Ruby – there are two standard libraries (they are built-in, so it is not necessary to install them): OptionParser and GetoptLong. Check them out. (thnx to Max)
The Choice library is an interesting choice, not only because it works smoothly, but it is a nice example of a domain specific language (DSL or see my older post about DSL in Ruby).