Skip to content

Commit 34a85b7

Browse files
committed
Merge pull request #390 from developingchris/boolean_negative
document negative option for boolean option
2 parents 54a0e17 + 2c4f421 commit 34a85b7

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

lib/thor/parser/option.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ def usage(padding = 0)
8585

8686
sample = "[#{sample}]" unless required?
8787

88+
if boolean?
89+
sample << ", [#{dasherize("no-" + human_name)}]" unless name == "force"
90+
end
91+
8892
if aliases.empty?
8993
(' ' * padding) << sample
9094
else

spec/parser/option_spec.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,11 +172,15 @@ def option(name, options = {})
172172
end
173173

174174
it 'returns usage for boolean types' do
175-
expect(parse(:foo, :boolean).usage).to eq('[--foo]')
175+
expect(parse(:foo, :boolean).usage).to eq('[--foo], [--no-foo]')
176176
end
177177

178178
it 'does not use padding when no aliases are given' do
179-
expect(parse(:foo, :boolean).usage).to eq('[--foo]')
179+
expect(parse(:foo, :boolean).usage).to eq('[--foo], [--no-foo]')
180+
end
181+
182+
it 'documents a negative option when boolean' do
183+
expect(parse(:foo, :boolean).usage).to include('[--no-foo]')
180184
end
181185

182186
it 'uses banner when supplied' do
@@ -197,6 +201,10 @@ def option(name, options = {})
197201
it 'does not show the usage between brackets' do
198202
expect(parse([:foo, '-f', '-b'], :required).usage).to eq('-f, -b, --foo=FOO')
199203
end
204+
205+
it 'does not negate the aliases' do
206+
expect(parse([:foo, '-f', '-b'], :boolean).usage).to eq('-f, -b, [--foo], [--no-foo]')
207+
end
200208
end
201209
end
202210
end

0 commit comments

Comments
 (0)