-
Notifications
You must be signed in to change notification settings - Fork 552
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
Add :case-insensitive flag to allow case-insensitive matching for :limited_to options 🌈 #644
Add :case-insensitive flag to allow case-insensitive matching for :limited_to options 🌈 #644
Conversation
lib/thor/shell/basic.rb
Outdated
say("Your response must be one of: [#{answers}]. Please try again.") unless correct_answer | ||
end | ||
correct_answer | ||
end | ||
|
||
def answer_match(possibilities, answer, case_insensitive) | ||
return possibilities.detect{ |possibility| possibility == answer } unless case_insensitive |
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.
can we change this to a if/else
?
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.
You're right; this isn't really a guard clause. I was all about guard clauses when I wrote this.
spec/shell/basic_spec.rb
Outdated
flavors = %w(strawberry chocolate vanilla) | ||
expect($stdout).to receive(:print).with("Your response must be one of: [strawberry, chocolate, vanilla]. Please try again.\n") | ||
expect(Thor::LineEditor).to receive(:readline).with('What\'s your favorite Neopolitan flavor? [strawberry, chocolate, vanilla] ', :limited_to => flavors).and_return("moose tracks", "chocolate") | ||
expect(shell.ask('What\'s your favorite Neopolitan flavor?', :limited_to => flavors)).to eq("chocolate") | ||
end | ||
|
||
#this one |
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.
#this one |
@rafaelfranca Changes addressed. Saw some seemingly unrelated test failures; they're persistent after rebasing off master. Seen these ones before? |
Thank you. Yeah. They are from a PR that I just merged. I'll fix them. |
Hey all,
After using thor a bit, I thought it'd be useful to be able to match a limited_to option case-insensitively. I often use it for [y/n] prompts, but having the prompt list out all the possibilities [y, Y, n, N, yes, YES, no, NO], for instance, doesn't looks so great. Adding case-insensitive matching allows me to simplify that prompt to [y, yes, n, no].
After reading the contributing guidelines, I see you'd like documentation updated, though documentation doesn't appear to be in the repo, but in a wiki instead. Let me know if there's anything you'd like to see added to this PR to move forward with it.
Thanks!