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

Print what is the validation that failed in the error message #15

Open
3v0k4 opened this issue May 19, 2024 · 0 comments
Open

Print what is the validation that failed in the error message #15

3v0k4 opened this issue May 19, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@3v0k4
Copy link

3v0k4 commented May 19, 2024

First of all, thanks for your work! I really appreciated the simplicity and power of this gem.

Describe the problem

Currently, the following validation:

argument :foo do
  validate /\d+/
end

Would return the following error when passed --foo bar:

"value of bar fails validation for '--foo' option"

But I have to check the source to know what is expected of --foo. Or hope it was documented in the desc.

How would the new feature work?

I'd like to either get something like (extracted with some Ruby magic):

"value of bar fails validation for '--foo' option, expected /\d+/"

Or, have the opportunity to specify the error message myself with something like:

argument :foo do
  validate /\d+/, "expected digit"
end

I'm happy to come up with a better API (and potentially a PR) for either version if this is a change that you'd like to have.

Drawbacks

Nothing as of now. But we may want to consider adding the same to the help.

@3v0k4 3v0k4 added the enhancement New feature or request label May 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant