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

Is there a way to ask again when failing check on prompt option #288

Closed
omuomugin opened this issue Apr 4, 2021 · 2 comments · Fixed by #313
Closed

Is there a way to ask again when failing check on prompt option #288

omuomugin opened this issue Apr 4, 2021 · 2 comments · Fixed by #313

Comments

@omuomugin
Copy link

Since I'm not sure already has this option to do, this is a question for "How to"

My UseCase is like below

When args were implemented like

private val name by option().prompt("Name")
        .check("Name should be less than 4 words "){ it.length <= 4 }

I want to have behavior like

$ cli_tool_made_by_clikt
Name: xxxxx # name by prompt option and should be less than 4 words
Error: Invalid value for Name:  Name should be less than 4 words # want to have failing immediately (1)
Name: # want to have it asking again (2)

Anyway thanks for the awesome framework

@ajalt
Copy link
Owner

ajalt commented Apr 5, 2021

So I agree that your proposed change is an improvement. The reason for the current behavior is that the lambdas for check and validate are called after the entire command line has been parsed. This lets you reference other options from those lambdas.

In order to implement re-prompt after validation failure, we would have to run that option's validation immediately. So there are two approaches:

  1. Run the validation for prompt options early, and document the behavior quirk
  2. Add a validation lambda to prompt specifically. I'm not a fan of this one; it's kludgy and doesn't work well with the rest of the API.

@omuomugin
Copy link
Author

Ok I understand that behavior.
Let me try implementing this if you don't mind.

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

Successfully merging a pull request may close this issue.

2 participants