spectre.console icon indicating copy to clipboard operation
spectre.console copied to clipboard

Async CommandSettings Validation

Open wbaldoumas opened this issue 2 years ago • 2 comments

Is your feature request related to a problem? Please describe.

From the docs, it looks like there's only an option to override a synchronous Validate method. There are many cases where it would be convenient to have async validation available by overriding a ValidateAsync method.

Describe the solution you'd like

Ideally, users of this library could override a Validate or ValidateAsync method, depending on their need for asynchrony during validation.

Describe alternatives you've considered

One alternative would be to use some of the strategies mentioned in this article to make async calls within a synchronous method. Each option listed there unfortunately does have drawbacks, though.

Additional context N/A


Please upvote :+1: this issue if you are interested in it.

wbaldoumas avatar Feb 10 '23 21:02 wbaldoumas

Hello @wbaldoumas (and anyone else coming across this issue), we are interested in the idea but are struggling to understand what the use case would be for async validation.

Could somebody please elaborate on why, and how, they would potentially use this feature?

FrankRay78 avatar Feb 18 '25 16:02 FrankRay78

I have done async validation but I wouldn't put it into the actual command settings validator. Or not in any case I have run across.

One case where I have done async validations is like such: The CLI took a command option that specified the path to a file that drives the rest of the command. The file contains a list of other files/paths to files that need to be processed.

Obviously, if the command takes an option to specify a path to a file. In my validator, the option is a FileInfo type I think? It's been a while. The validate that FileInfo.Exists

To run properly the file also needs to have data in it and that data is just a list of other files that need to be processed by the CLI. The input file was like accumulating a batch of files to process if that makes sense. I needed to validate that the input file is correct and all the files it lists exist etc. But to me, that is beyond the scope of simple command settings validation.

I put that logic into the ExecuteAsync to handle the Disk I/O operations and provide status indicators if something is long-running. I wouldn't try to do all of that in the settings validator.

I am curious about the use case here as well and the possible work involved in being able to configure how the progress/status of the long-running validation appears to the user.

byte2pixel avatar Feb 18 '25 17:02 byte2pixel

Agreed, I intended to do some async validation for my app - querying a web API to check if a project exists prior to submitting a time record for it, but I think it falls better under ExecuteAsync().

I can understand why the desire for async validation however.

IHash223 avatar Sep 13 '25 08:09 IHash223