dotnet / dotnet/command-line-api
best way to add option validator
Open
Area-Parser and Binder
question
- Dominant language
- C#
- Stars
- 3.7k
- Forks
- 428
- PR merge metrics
- No merged PRs in 30d
Description
What is the best way to add a validator for option parse? Is "AddValidator" best here? How is to allow await statement inside validator logic that makes a db call suppose?? It works for sync but not async - maybe delegate needs to be wrapped .. could not get an example, so reaching for help.
```
var coption = new Option("-c");
coption.FromAmong>("-", ".", "_");
coption.AddValidator(symbol => {
var pvalue = symbol.GetValueOrDefault();
//await Task.Delay(2000);
// logic for pvalue check
return null;
});
```
Looking forward for suggestion!
Contributor guide
Assessment
This issue has not been assessed yet.