Skip to content

When options are not found

Jason Frey edited this page Aug 24, 2018 · 3 revisions

When an unknown option is given, Optimist will return an unknown argument message by default.

$ ./lesshelp.rb -x
Error: unknown argument '-x'.
Try --help for help.

Adding educate_on_error will display the help message instead (via educate).

require 'optimist'
opts = Optimist::options do
  opt :cat, "A cat option"
  educate_on_error
end
$ ./morehelp.rb -x
Error: unknown argument '-x'.

Options:
  -c, --cat     A cat option
  -h, --help    Show this message