Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mandatory options? #3

Open
ggilder opened this issue Apr 1, 2015 · 9 comments
Open

Mandatory options? #3

ggilder opened this issue Apr 1, 2015 · 9 comments

Comments

@ggilder
Copy link
Member

ggilder commented Apr 1, 2015

From @deric on October 21, 2013 13:44

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

Copied from original issue: tj/commander#62

@ggilder
Copy link
Member Author

ggilder commented Apr 1, 2015

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

@ggilder
Copy link
Member Author

ggilder commented Apr 1, 2015

From @deric on October 28, 2013 8:16

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.

@ggilder
Copy link
Member Author

ggilder commented Apr 1, 2015

From @sihil on November 11, 2013 17:57

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

@ggilder
Copy link
Member Author

ggilder commented Apr 1, 2015

From @mattes on March 27, 2014 2:19

👍

@ggilder
Copy link
Member Author

ggilder commented Apr 1, 2015

From @odcinek on May 1, 2014 13:8

👍

@ggilder
Copy link
Member Author

ggilder commented Apr 1, 2015

From @sdogruyol on August 9, 2014 18:28

Is there any update on this ?

@ggilder
Copy link
Member Author

ggilder commented Apr 1, 2015

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.

@ggilder
Copy link
Member Author

ggilder commented Apr 1, 2015

From @Sovietaced on March 25, 2015 7:18

👍

@Sovietaced
Copy link

I just gave it a shot but didn't get very far. I'm not that familiar with ruby but when I see really idiomatic ruby code I get confused as hell. Going to abort.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants