davetron5000 / gli

Make awesome command-line applications the easy way
http://davetron5000.github.io/gli
Apache License 2.0
1.26k stars 102 forks source link

Flag's required is not enforced on CLI #251

Closed itsSaad closed 8 years ago

itsSaad commented 8 years ago

im using it as:

  c.flag [:e, :environment], arg_name: 'environment_name', desc: "Environment to provision", type: "String", required: true

requried: true is there. but when i use it as bundle exec bin/face provision on command line. One expects to see an error mentioning you missed a required flag.But it goes through without.

davetron5000 commented 8 years ago

This isn't broken for me—can you post your repo or a minimal repo that reproduces this?

itsSaad commented 8 years ago

Sorry for trouble. Actually it works. mine wasnt because mine was raising a #<LocalJumpError: unexpected return> when i used return true in the pre block instead of true. Do you know what that is about?

davetron5000 commented 8 years ago

Yeah, return in Ruby is only really intended to be used inside a method definition. If you use it inside a block (which is what pre is taking), Ruby tries to return from whatever method that block is. My guess is that it's confused because in your GLI app, you aren't inside a method, but in the special main object. This stackoverflow question has a bit more detail.

itsSaad commented 8 years ago

oh. thanks a lot for clearing that up. never thought of it for the last 4 years.