Skip to content

Commit

Permalink
Allow --no-foo to be given as --skip-foo.
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim committed Jun 26, 2009
1 parent 8cc72b2 commit 392cd4a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/thor/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def switch?(arg)
# Returns the option object for the given switch.
#
def switch_option(arg)
if arg =~ /^--no-(\w+)$/
if arg =~ /^--(no|skip)-(\w+)$/
@switches[arg] || @switches["--#{$1}"]
else
@switches[arg]
Expand All @@ -177,7 +177,7 @@ def parse_option(switch, option, hash)
when :default
hash[human_name] = peek.nil? || peek.to_s =~ /^-/ || shift
when :boolean
if !@switches.key?(switch) && switch =~ /^--no-(\w+)$/
if !@switches.key?(switch) && switch =~ /^--(no|skip)-(\w+)$/
hash[$1] = false
else
hash[human_name] = true
Expand Down
9 changes: 9 additions & 0 deletions spec/options_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,19 @@ def sorted_usage
parse("--no-foo")["foo"].must == false
end

it "accepts --[skip-]opt variant, setting false for value" do
parse("--skip-foo")["foo"].must == false
end

it "will prefer 'no-opt' variant over inverting 'opt' if explicitly set" do
create "--no-foo" => true
parse("--no-foo")["no-foo"].must == true
end

it "will prefer 'skip-opt' variant over inverting 'opt' if explicitly set" do
create "--skip-foo" => true
parse("--skip-foo")["skip-foo"].must == true
end
end

describe "with :hash type" do
Expand Down

0 comments on commit 392cd4a

Please sign in to comment.