dotnet / dotnet/command-line-api

Custom validation of arguments

Open
#476 8 comments 3 reactions 0 assignees View on GitHub
needs documentation
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.