Skip to content

Commit d65fef7

Browse files
Aurelien Derouineauaderouineau
authored andcommitted
Do not generate a negative option (--no-no-foo) for already negative boolean options (--no-foo)
1 parent e5e77c4 commit d65fef7

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

lib/thor/parser/option.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def usage(padding = 0)
8686
sample = "[#{sample}]" unless required?
8787

8888
if boolean?
89-
sample << ", [#{dasherize("no-" + human_name)}]" unless name == "force"
89+
sample << ", [#{dasherize("no-" + human_name)}]" unless name == "force" or name.start_with?("no-")
9090
end
9191

9292
if aliases.empty?

spec/parser/option_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,14 @@ def option(name, options = {})
189189
expect(parse(:foo, :boolean).usage).to include("[--no-foo]")
190190
end
191191

192+
it "does not document a negative option for a negative boolean" do
193+
expect(parse(:'no-foo', :boolean).usage).not_to include("[--no-no-foo]")
194+
end
195+
196+
it "documents a negative option for a positive boolean starting with 'no'" do
197+
expect(parse(:'nougat', :boolean).usage).to include("[--no-nougat]")
198+
end
199+
192200
it "uses banner when supplied" do
193201
expect(option(:foo, :required => false, :type => :string, :banner => "BAR").usage).to eq("[--foo=BAR]")
194202
end

0 commit comments

Comments
 (0)