commandlineparser / commandline

The best C# command line parser that brings standardized *nix getopt style, for .NET. Includes F# support
MIT License
4.46k stars 473 forks source link

How to add constraints to an int option? #905

Open loudenvier opened 8 months ago

loudenvier commented 8 months ago

Is it possible to set constraints to an int option so that it have min and max allowed values? I think that's a pretty common scenario, but the following fails:

[Option('q', "quality", Default = 80, Min = 1, Max = 100)]
public int Quality { get; set; }    

With this exception: System.InvalidOperationException: Scalar option specifications do not support range specification.

If the library does not provide this functionality how would I implement it on my own and still play nicely with the auto help and error messages that the library automatically outputs on invalid input?