Skip to content
Open
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
4 changes: 3 additions & 1 deletion lib/thor/parser/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@ def initialize(hash_options = {}, defaults = {}, stop_on_unknown = false, disabl
super(options)

# Add defaults
option_lookup = Thor::CoreExt::HashWithIndifferentAccess.new(hash_options)

defaults.each do |key, value|
@assigns[key.to_s] = value
@non_assigned_required.delete(hash_options[key])
@non_assigned_required.delete(option_lookup[key])
end

@shorts = {}
Expand Down
12 changes: 12 additions & 0 deletions spec/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,18 @@ def hello
expect(base.options[:third]).to eq(4)
end

it "allows required options to be given as symbols or strings" do
counter = Class.new(MyCounter) do
class_option :third, required: true, type: :numeric
end

base = counter.new [1, 2], third: 4
expect(base.options[:third]).to eq(4)

base = counter.new [1, 2], "third" => 4
expect(base.options[:third]).to eq(4)
end

it "creates options with indifferent access" do
base = MyCounter.new [1, 2], third: 3
expect(base.options["third"]).to eq(3)
Expand Down