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

[QUESTION] Validate input arguments without running the command #489

Closed
alegomes opened this issue Feb 18, 2024 · 1 comment · Fixed by #508
Closed

[QUESTION] Validate input arguments without running the command #489

alegomes opened this issue Feb 18, 2024 · 1 comment · Fixed by #508

Comments

@alegomes
Copy link

Is it possible to validate the command's input arguments without having to execute it?

What I want:

assertFailsWith<SomeCliktError> {
    MyCommand().parse(listOf("..."))
}

...but without necessarily executing the command, which is cost-intensive.

I followed the CliktCommand.parse() > Parser.parse() > command.run() execution stack, but I didn't see a way to run Parser.parse() with the canRun=false parameter.

thanks a lot
Alexandre

@ajalt
Copy link
Owner

ajalt commented Feb 18, 2024

This has been discussed before in #449.

run is called in the middle of parsing. If we skipped run, it could result in different behavior, which is why I haven't added this feature.

But since multiple people have asked for it, it might be worth adding, maybe as a property on the context.

In the mean time, you could add your own dry run property that you check in run if you need it.

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