Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions lib/lrama/option_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,9 @@ def parse_by_option_parser(argv)
o.on('-t', '--debug', 'display debugging outputs of internal parser') {|v| @options.debug = true }
o.separator " same as '-Dparse.trace'"
o.on('--locations', 'enable location support') {|v| @options.locations = true }
o.on('-D', '--define=NAME[=VALUE]', Array, "similar to '%define NAME VALUE'") do |v|
@options.define = v.each_with_object({}) do |item, hash| # steep:ignore UnannotatedEmptyCollection
key, value = item.split('=', 2)
hash[key] = value
end
o.on('-D', '--define=NAME[=VALUE]', "similar to '%define NAME VALUE'") do |v|
key, value = v.split('=', 2)
@options.define[key] = value
end
o.separator ''
o.separator 'Output:'
Expand Down
9 changes: 9 additions & 0 deletions spec/lrama/option_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -403,5 +403,14 @@
end
end
end

context "when multiple define options are passed" do
it "returns hash of define options" do
option_parser = Lrama::OptionParser.new
option_parser.send(:parse, ["--define=foo=1", "--define=bar", fixture_path("command/basic.y")])
options = option_parser.instance_variable_get(:@options)
expect(options.define).to eq({'foo' => "1", 'bar' => nil})
end
end
end
end
Loading