Project

General

Profile

Actions

Bug #14728

closed

OptionParser takes other options as argument values

Added by xz0r (xz0r xz0r) almost 6 years ago. Updated almost 6 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
ruby -v:
ruby 2.0.0p648 (2015-12-16 revision 53162) [universal.x86_64-darwin16]
[ruby-core:86798]

Description

test.rb

require 'optparse'

options = {}
OptionParser.new do |opts|
  opts.banner = "Usage: test.rb [options]"

  opts.on("--verbose", "Run verbosely") do |v|
    options[:verbose] = v
  end
  opts.on("--custom MANDATORY", "custom") do |x|
    options[:custom] = x
  end
end.parse!

p options

If I run the above script as follows below is output:

$ ruby test.rb --custom --verbose
{:custom=>"--verbose"}

This is not the expected behaviour as --verbose should not be set as the option value.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0