From: paulo.fidalgo.pt@... Date: 2021-04-22T21:09:52+00:00 Subject: [ruby-core:103566] [Ruby master Bug#17821] Impossible to define only short versions of options in OptionParser Issue #17821 has been reported by fidalgo (Paulo Fidalgo). ---------------------------------------- Bug #17821: Impossible to define only short versions of options in OptionParser https://bugs.ruby-lang.org/issues/17821 * Author: fidalgo (Paulo Fidalgo) * Status: Open * Priority: Normal * ruby -v: ruby 3.0.1p64 (2021-04-05 revision 0fb782ee38) [x86_64-linux] * Backport: 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN ---------------------------------------- I have tried several approaches and either I'm being misled by the documentation or there's a bug. I've tried this with two versions of ruby 2.7.2 and 3.0.1, both compiled using rbenv. Here is the code: ``` require 'optparse' options = {} OptionParser.new do |opts| opts.banner = "Usage: #{$PROGRAM_NAME} [options]" opts.on('-na', 'Numbers for the first column') { |o| options[:na] = o } opts.on('-sa', 'Stars for the first column') { |o| options[:sa] = o } opts.on('-nb', 'Numbers for the first column') { |o| options[:nb] = o } opts.on('-sb', 'Stars for the first column') { |o| options[:sb] = o } if ARGV.empty? puts opts.help exit 1 end end.parse!(into: options) p options ``` and the output: ``` ruby options.rb Usage: options.rb [options] -nb Numbers for the first column -sb Stars for the first column ``` The bug happens because we should have four different options on the help. -- https://bugs.ruby-lang.org/ Unsubscribe: