Closed KINGSABRI closed 4 years ago
Can you share the code to your app at all? help_now
raises an exception, but the intention is that the exception is caught and prints out the help instead. But as you can see, there are ways to prevent that and the error will bubble up.
Hi @davetron5000 Yes, the code is here (https://github.com/KINGSABRI/jwtear)
Ah, I see the issue. Because you've overridden on_error
, GLI won't do its default handling if you don't return true
from the block. Looks like you are exiting directly from there, but you don't have to do that.
Check out the docs to see how it works, but basically if you return true
from on_error
, it will use GLI's custom error handling and should print out the help text.
Great, Thank you. Regarding the logo, I want to print the logo only on the help not on every command executing
If you mean what OptionParse calls the "banner", it looked the code is puts
ing it every time.
correct, and that's the problem. I want the banner to be printed only when the help menu is printed
Yeah, sorry if I wasn't more clear. You need to remove that puts
statement from your app that I linked to above. That will keep it printing the banner every time.
Then, change your on_error
block so that it returns true
. That will print the banner (and other help output) when you call help_now!
in your code.
Thank you @davetron5000 for your instant support. It worked for me now
For people who are facing the same case, here is the solution.
on_error do |exception|
puts banner
# ... your custom exception handling code ...
true
end
Hi I could not find a way from the wiki to print the script logo only when the help menu shows up. How to print the help menu as we do with OptionParse. I tried
help_now!
in the main app and from within the command itself and I get an error similar toThanks!