Skip to content
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

Allow messages to be passed as keyword argument #197

Open
lulalala opened this issue Dec 21, 2023 · 1 comment
Open

Allow messages to be passed as keyword argument #197

lulalala opened this issue Dec 21, 2023 · 1 comment
Labels

Comments

@lulalala
Copy link

Describe the problem

Allow messages to be passed as keyword argument. This is handy for us because we don't want to use a block to configure the ask, instead have prepared a hash to be used as keyword arguments. Hash works better for more dynamic scenarios.

Steps to reproduce the problem

Using this as a starting, working example which would prompt the user if input is invalid:

prompt.ask("What is your email?") do |q|
  q.validate(/\A\w+@\w+\.\w+\Z/)
  q.messages[:valid?] = "Invalid email address"
end

If I move the validate into the keyword argument, it also works fine:

prompt.ask("What is your email?", validate: /\A\w+@\w+\.\w+\Z/ ) do |q|
  q.messages[:valid?] = "Invalid email address"
end

However, once I move messages into the keyword argument:

prompt.ask("What is your email?", validate: /\A\w+@\w+\.\w+\Z/, messages: { valid?: 'foo' } ) 

The custom messages no longer works. It would display the default "Your answer is invalid (must match /\A\w+@\w+.\w+\Z/)"

Actual behaviour

The custom messages can't be passed as keyword arguments.

Expected behaviour

The custom messages can be passed as keyword arguments.

Describe your environment

  • OS version:
  • Ruby version: 3.1
  • TTY::Prompt version: 0.23.1
@piotrmurach
Copy link
Owner

Hi @lulalala 👋

Thank you for reporting this issue. This is a bug, the messages should work as an option as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants