#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.

Note

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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.