JEG2 / highline

A higher level command-line oriented interface.
Other
1.29k stars 137 forks source link

Proc validation displays ruby object on invalid #219

Closed jblaine closed 7 years ago

jblaine commented 7 years ago

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>).

abinoam commented 7 years ago

Thanks, I'll take a look at it. Just confirm you're using 2.0.0-prerelease version.

abinoam commented 7 years ago

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.

jblaine commented 7 years ago

@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.

abinoam commented 7 years ago

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.

abinoam commented 7 years ago

@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?

abinoam commented 7 years ago

Feedback = Has this featured worked on your use case?

jblaine commented 7 years ago

Tried 2.0.0.pre.develop.13 and the Proc response works fine for our use case.

abinoam commented 7 years ago

Thanks for your feedback @jblaine! 👍