#7 Command-Line Interface (uses_cli.rb and simple_cli.rb)

The program uses_cli.rb understands command-line options, which are configuration options that you can use to make the script behave in different ways, depending on the specific values chosen. It uses specific options that have become somewhat standard, such as -h or --help. Options in the form with a single hyphen and a single letter are short options, while those with a double hyphen and a full word are (unsurprisingly) called long options. Let’s look at the code for uses_cli.rb.


I think there is enough pedagogical value to rolling your own command-line parser to make it worthwhile, especially in a book like this. However, I should note that there are two fine built-in CLI parsers ...

Get Ruby by Example now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.