| 1 | require 'optparse' |
| 2 | parser = OptionParser.new |
| 3 | parser.on('-x', '--xxx', 'Short and long, no argument') |
| 4 | parser.on('-yYYY', '--yyy', 'Short and long, required argument') |
| 5 | parser.on('-z [ZZZ]', '--zzz', 'Short and long, optional argument') |
| 6 | options = {} |
| 7 | parser.parse!(into: options) |
| 8 | required_options = [:xxx, :zzz] |
| 9 | missing_options = required_options - options.keys |
| 10 | unless missing_options.empty? |
| 11 | fail "Missing required options: #{missing_options}" |
| 12 | end |