Skip to content

Commit 605897b

Browse files
committed
Output warning instead of raising an exepection on default type mismatch
See #435 (comment) Closes #533.
1 parent a074db0 commit 605897b

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

lib/thor/parser/option.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ def validate_default_type!
127127
@default.class.name.downcase.to_sym
128128
end
129129

130-
raise ArgumentError, "An option's default must match its type." unless default_type == @type
130+
# TODO: This should raise an ArgumentError in a future version of Thor
131+
warn "Expected #{@type} default value for '#{switch_name}'; got #{@default.inspect} (#{default_type})" unless default_type == @type
131132
end
132133

133134
def dasherized?

spec/parser/option_spec.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,9 @@ def option(name, options = {})
135135
end
136136

137137
it "raises an error if default is inconsistent with type" do
138-
expect do
139-
option("foo", :type => :numeric, :default => "bar")
140-
end.to raise_error(ArgumentError, "An option's default must match its type.")
138+
expect(capture(:stderr) do
139+
option("foo_bar", :type => :numeric, :default => "baz")
140+
end.chomp).to eq('Expected numeric default value for \'--foo-bar\'; got "baz" (string)')
141141
end
142142

143143
it "does not raises an error if default is an symbol and type string" do

0 commit comments

Comments
 (0)