Skip to content

Commit

Permalink
Merge pull request #390 from developingchris/boolean_negative
Browse files Browse the repository at this point in the history
document negative option for boolean option
  • Loading branch information
sferik committed Mar 22, 2014
2 parents 54a0e17 + 2c4f421 commit 34a85b7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 4 additions & 0 deletions lib/thor/parser/option.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ def usage(padding = 0)

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

if boolean?
sample << ", [#{dasherize("no-" + human_name)}]" unless name == "force"
end

if aliases.empty?
(' ' * padding) << sample
else
Expand Down
12 changes: 10 additions & 2 deletions spec/parser/option_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,15 @@ def option(name, options = {})
end

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

it 'does not use padding when no aliases are given' do
expect(parse(:foo, :boolean).usage).to eq('[--foo]')
expect(parse(:foo, :boolean).usage).to eq('[--foo], [--no-foo]')
end

it 'documents a negative option when boolean' do
expect(parse(:foo, :boolean).usage).to include('[--no-foo]')
end

it 'uses banner when supplied' do
Expand All @@ -197,6 +201,10 @@ def option(name, options = {})
it 'does not show the usage between brackets' do
expect(parse([:foo, '-f', '-b'], :required).usage).to eq('-f, -b, --foo=FOO')
end

it 'does not negate the aliases' do
expect(parse([:foo, '-f', '-b'], :boolean).usage).to eq('-f, -b, [--foo], [--no-foo]')
end
end
end
end

0 comments on commit 34a85b7

Please sign in to comment.