-
Notifications
You must be signed in to change notification settings - Fork 36
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
adding support for DidYouMean when long options are spelled incorrectly #150
Conversation
|
lib/optimist.rb
Outdated
# instance_eval(&b) if b # can't take arguments | ||
cloaker(&b).bind(self).call(*a) if b | ||
#cloaker(&b).bind(self).call(*a) if b |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this line just be deleted? I'm curious why you stopped using the cloaker.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, should be deleted, I just removed the call to it and the cloaker method.
AFAICT the cloaker was a super clever trick used before instance_exec
was in ruby, since instance_eval
didnt support passing a block, but i could be wrong about that...
In any event, instance_exec seems to work such that all tests pass and doesnt require weird trickery, so felt like the cloaker could be safely removed.
Added: - Align the short and long forms into their own columns in the help output (#145 - thanks akhoury6) - Add support for DidYouMean when long options are spelled incorrectly (#150 - thanks nanobowers) - Using `permitted:` restricts the allowed values that a end-user inputs to a pre-defined list (#147 - thanks akhoury6) - Add exact_match to settings, defaulting to inexact matching (#154 - thanks nanobowers) - Add setting to disable implicit short options (#155 - thanks nanobowers) - Add alt longname and multiple char support (#151 - thanks nanobowers) - Permitted regexp/range support (#158, #159- thanks nanobowers) - Add some examples (#161 - thanks nanobowers) Changed: - Enable frozen_string_literal for future-ruby support (#149, #153 - thanks nanobowers) - Refactor constraints (#156 - thanks nanobowers) - Fix assert_raises to assert_raises_errmatch (#160 - thanks nanobowers)
Enables "did_you_mean" style suggestions for long options.
This works similar to how it does when you misspell something in Ruby, but applied to long options in Optimist.
It uses the same string-distance algorithm as Ruby to see if any of the long options are within a reasonable distance. The
DidYouMean
feature was added in ruby2.3, so this will not work with older rubies but I dont believe we support those anymore.There is a keyword option that can be passed in at the Optimist.options() level to disable suggestions, e.g.
Optimist.options(ARGV, suggestions: false)
and get legacy behavior. Some tweaks to how options are merged was necessary for this.examples script and output provided in the
/examples
directory.@miq-bot add-label enhancement
@miq-bot add-reviewer @Fryguy