cldwalker / boson

A command/task framework similar to rake and thor built with extendability in mind.
http://rdoc.info/gems/boson
MIT License
218 stars 10 forks source link

boolean options cannot default to false #40

Open Edgy opened 12 years ago

Edgy commented 12 years ago

There is an inconsistency in giving boolean options a true or false as a default value. I've noticed this issue since atleast version 0.3.4.

Given this code:

module Foo

  option :urgent, type: :boolean, default: false
  # Does a WTF
  def wtf(argv={})
    puts "ARGV: #{argv.inspect}"
  end
end

We get this output:

1 $ boson wtf
ARGV: {}
2 $ boson wtf -u
ARGV: {:urgent=>true}
3 $ boson wtf --no-u
ARGV: {:urgent=>false}

Now if we set the default value to true we get:

module Foo

  option :urgent, type: :boolean, default: true
  # Does a WTF
  def wtf(argv={})
    puts "ARGV: #{argv.inspect}"
  end
end

And this output:

1 $ boson wtf
ARGV: {:urgent=>true}
2 $ boson wtf -u
ARGV: {:urgent=>true}
3 $ boson wtf --no-u
ARGV: {:urgent=>false}

You'll notice that if we run boson w/o an argument and the default is set to 'false', we don't get the expected "ARGV: {:urgent=>false}" as we find when we set the default to 'true'.

Thanks for taking a look at this.

cldwalker commented 12 years ago

Thanks for the detailed bug report. Surprised I haven't come across this. Will take a look.