Option attribute based upon enum does not allow to override validation behaviour
See original GitHub issueMaybe not a bug, but I have this enum for an option, and when provided with an invalid enum, I do see the standard error message. However, I want to be able to provide or:
- my custom validation message
- ShowHelp()
Please note that in my case I just run CommandLineApplication.Execute<GeneratorCommand>(args);
so I have to access to the CommandLineApplication
instance to subscribe to ValidationErrorHandler
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Make validation fail for a certain enum value with asp.net mvc
Enums are basically integers so you can use the Range attribute to validate ... return new ValidationResult("This value is not allowed"); ...
Read more >TypeScript string enums, and when and how to use them
No matter how much you know about TypeScript enums, this guide covers all the best practices for using string-based enums in production.
Read more >enum — Support for enumerations
An enumeration with the values STRICT , CONFORM , EJECT , and KEEP which allows for more fine-grained control over how invalid values...
Read more >How to write custom converters for JSON serialization - .NET
To override the default behavior of a built-in converter. For example, you might want DateTime values to be represented by mm/dd/yyyy format ...
Read more >Define Enum Fields and Suggested Values in the UI
Learn how to define enums and suggested values for string fields in the Experience Platform user interface.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Great! Thanks for this quick feedback!
Not from inside the parsers. There is no application in the context of IValueParser.Parse. The expected way to implement this API is to parse or throw FormatException.
If you want to call ShowHelp, I’d recommend catching
CommandParsingException
at the top level. Give this a try:As you can see in the implementation,
CommandLineApplication.Execute<T>(args)
doesn’t do much more than this. https://github.com/natemcmaster/CommandLineUtils/blob/ecfc8bc3992f9ee899115622dcb851d0274f3557/src/CommandLineUtils/CommandLineApplication.Execute.cs#L51-L64