commander-rb / commander

The complete solution for Ruby command-line executables
MIT License
822 stars 74 forks source link

How to parse boolean switches #66

Closed evannorstrand closed 6 years ago

evannorstrand commented 6 years ago

I would like to run a command that works like this:

command --foo true --bar true

but look like this:

command --foo --bar

Is this possible?

ggilder commented 6 years ago

Yes, the following will do what you want:

command :mycommand do |c|
  c.option '--something', 'Some switch that does something'
  c.action do |args, options|
    puts options.some_switch # this will be true when the switch is provided and nil otherwise
  end
end
evannorstrand commented 6 years ago

Can this be documented in the README somewhere?

ggilder commented 6 years ago

If you'd like to take a stab at a pull request to add it to the readme that'd be great!