dotnet / dotnet/command-line-api
Custom validation of arguments
- Dominant language
- C#
- Stars
- 3.7k
- Forks
- 428
- PR merge metrics
- No merged PRs in 30d
Description
At which place do I implement custom validation for the CLI arguments? For example I got one argument that is not optional and has to be set, or I want to validate an connection string which is provided through the CLI.
Currently I'm creating and using a command handler like that:
`rootCommand.Handler = CommandHandler.Create(arguments =>`
Hereby the CLI arguments are used to create the `ProgramArguments` class. But when I throw an Exception in the constructor of that class it's not handled anywhere.
It seems that it's also not possible to catch that exception when wrapping `return rootCommand.InvokeAsync(args, new SystemConsole()).Result;` in a try catch block.
Contributor guide
Assessment
This issue has not been assessed yet.