diff --git a/lib/thor/parser/option.rb b/lib/thor/parser/option.rb index f53d6d70..b1a99431 100644 --- a/lib/thor/parser/option.rb +++ b/lib/thor/parser/option.rb @@ -104,6 +104,15 @@ def aliases_for_usage end end + def show_default? + case default + when TrueClass, FalseClass + true + else + super + end + end + VALID_TYPES.each do |type| class_eval <<-RUBY, __FILE__, __LINE__ + 1 def #{type}? diff --git a/spec/parser/option_spec.rb b/spec/parser/option_spec.rb index 1b93f132..54aba1bb 100644 --- a/spec/parser/option_spec.rb +++ b/spec/parser/option_spec.rb @@ -269,4 +269,21 @@ def option(name, options = {}) end end end + + describe "#print_default" do + it "prints boolean with true default value" do + expect(option(:foo, { + required: false, + type: :boolean, + default: true + }).print_default).to eq(true) + end + it "prints boolean with false default value" do + expect(option(:foo, { + required: false, + type: :boolean, + default: false + }).print_default).to eq(false) + end + end end