-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix require_exact
to work with options defined as --[no]-something
#60
Conversation
@@ -1048,7 +1048,7 @@ def compsys(to, name = File.basename($0)) # :nodoc: | |||
# Shows option summary. | |||
# | |||
Officious['help'] = proc do |parser| | |||
Switch::NoArgument.new do |arg| | |||
Switch::NoArgument.new(nil, nil, ["-h"], ["--help"]) do |arg| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this related to the require_exact
bug fix?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without it we will get a no method error on nil (here https://github.com/ruby/optparse/pull/60/files#diff-efe4cf792254b968b88d74bf0c0072b5caba64bacfaa0bb43e2a019e7a339518R1645) when just calling $ cli --help
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't reproduce that failure even without this part of the change.
Reproduction test script: # cli.rb
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
# Activate the gem you are reporting the issue against.
gem "optparse", github: "ruby/optparse"
end
require "optparse"
options = OptionParser.new do |opts|
opts.require_exact = true
opts.on("-v", "--[no-]verbose", "Run verbosely") do
# ...
end
end
options.parse!
|
To work with options defined as `--[no]-something`. Fix ruby/optparse#60 ruby/optparse@c5ddf23f52
To work with options defined as `--[no]-something`. Fix https://bugs.ruby-lang.org/issues/20252 Fix ruby/optparse#60 ruby/optparse@d4c9162f5e
To work with options defined as `--[no]-something`. Fix https://bugs.ruby-lang.org/issues/20252 Fix ruby/optparse#60 ruby/optparse@78afdab307
To work with options defined as `--[no]-something`. Fix https://bugs.ruby-lang.org/issues/20252 Fix #60
While working on rubocop/rubocop#12282 I identified that
optparse
does not work correctly whenrequire_exact
is set and an option with--[no-]
prefix is defined. It raisesinvalid option
when this option is provided via command line.Example
This config was introduced in #2.
cc @jeremyevans (as implementor)