Skip to content

Commit 06dade7

Browse files
committed
Do not raise when default is boolean and option is required
1 parent 31150ee commit 06dade7

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

lib/thor/parser/option.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def validate_default_type!
116116
when nil
117117
return
118118
when TrueClass, FalseClass
119-
:boolean
119+
required? ? :string : :boolean
120120
when Numeric
121121
:numeric
122122
when Symbol

spec/parser/option_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,12 @@ def option(name, options = {})
153153
end.to raise_error(ArgumentError, "An option cannot be boolean and required.")
154154
end
155155

156+
it "does not raises an error if default is a boolean and it is required" do
157+
expect do
158+
option("foo", :required => true, :default => true)
159+
end.not_to raise_error
160+
end
161+
156162
it "allows type predicates" do
157163
expect(parse(:foo, :string)).to be_string
158164
expect(parse(:foo, :boolean)).to be_boolean

0 commit comments

Comments
 (0)