Closed jblaine closed 7 years ago
Thanks, I'll take a look at it. Just confirm you're using 2.0.0-prerelease version.
Hi @jblaine,
You can overwrite the default responses like this.
require 'highline'
cli = HighLine.new
cli.ask("A question to be validated against a lambda") do |q|
# Some kind of validation logic
# If lambda returns a truethy value, it's validated
q.validate = ->(answer){ false }
# As there's no easy way HighLine could infer what happens inside
# the lambda, you may override the default responses.
q.responses[:not_valid] = "Some customized message"
end
See: http://www.rubydoc.info/github/JEG2/highline/master/HighLine%2FQuestion:responses
Do you think this can help at your use case?
Unfortunatelly, this answer is a static String.
If I have some spare time I can try and see if I can make it accept a lambda so we can give a response according to user answer.
@abinoam The hardcoded string response will work well enough for us for now. Thanks for the speedy reply and thanks for making highline available for everyone.
Thank you for your feedback. I'll let this issue open as a reminder to me. I'll try to find time to do it.
@jblaine I have just released 2.0.0-develop.13 from PR #220. Now you can use a proc or a string. The given user answer will be yielded/passed to the lambda/proc. Could you give me any feedback on this?
Feedback = Has this featured worked on your use case?
Tried 2.0.0.pre.develop.13 and the Proc response works fine for our use case.
Thanks for your feedback @jblaine! 👍
Is there a way to make this more useful to the user when using a Proc for validation?
Your answer isn't valid (must match #<Proc:0x005595f1ced3f8@account:85>).