tj / commander

The complete solution for Ruby command-line executables
http://visionmedia.github.com/commander
MIT License
1.09k stars 64 forks source link

Mandatory options? #62

Closed deric closed 9 years ago

deric commented 11 years ago

Is it possible to specify an option which will be required in order to run command?

ggilder commented 11 years ago

There's not an automatic way to do that, but you could use something like this:

command :bar do |c|
  c.option '--prefix STRING', String, 'Adds a prefix to bar'
  c.action do |args, options|
    raise ArgumentError.new("Prefix is required!") unless options.prefix
    # ... normal command stuff here ...
  end
end
deric commented 11 years ago

Ok, thanks. It would be nice to have something like this:

command :bar do |c|
  c.option '--prefix STRING', String, 'Adds a prefix to bar', :mandatory => true
   # ...
end

When mandatory option would be missing, usage will be printed.

sihil commented 10 years ago

I'd like to see an easy way to have mandatory options as well.

mattes commented 10 years ago

:+1:

odcinek commented 10 years ago

:+1:

sdogruyol commented 10 years ago

Is there any update on this ?

ggilder commented 10 years ago

Pull requests are welcome! I think this would not be too tricky to implement. In the meantime there's always the workaround I posted above.

Sovietaced commented 9 years ago

:+1:

ggilder commented 9 years ago

This issue was moved to commander-rb/commander#3