Skip to content
Snippets Groups Projects
Commit 4c833b24 authored by Markus Reiter's avatar Markus Reiter
Browse files

Fix parsing of negative options.

parent 2a619a9c
No related branches found
No related tags found
No related merge requests found
......@@ -73,6 +73,12 @@ module Homebrew
description = option_to_description(*names) if description.nil?
process_option(*names, description)
@parser.public_send(method, *names, *wrap_option_desc(description)) do |value|
value = if names.any? { |name| name.start_with?("--[no-]") }
value
else
true
end
set_switch(*names, value: value, from: :args)
end
......
......@@ -15,7 +15,7 @@ describe Homebrew::CLI::Parser do
allow(Homebrew::EnvConfig).to receive(:pry?).and_return(true)
end
context "when using negative options" do
context "when using binary options" do
subject(:parser) {
described_class.new do
switch "--[no-]positive"
......@@ -33,6 +33,30 @@ describe Homebrew::CLI::Parser do
end
end
context "when using negative options" do
subject(:parser) {
described_class.new do
switch "--no-positive"
end
}
it "does not set the positive name" do
args = parser.parse(["--no-positive"])
expect(args.positive?).to be nil
end
it "fails when using the positive name" do
expect {
parser.parse(["--positive"])
}.to raise_error(/invalid option/)
end
it "sets the negative name to true if the negative flag is passed" do
args = parser.parse(["--no-positive"])
expect(args.no_positive?).to be true
end
end
context "when `ignore_invalid_options` is true" do
it "passes through invalid options" do
args = parser.parse(["-v", "named-arg", "--not-a-valid-option"], ignore_invalid_options: true)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment