fclp / fluent-command-line-parser

A simple, strongly typed .NET C# command line parser library using a fluent easy to use interface
Other
533 stars 86 forks source link

Feature request: .NotNull() check for command options #97

Open agracio opened 6 years ago

agracio commented 6 years ago

It would be great if both required and optional options could be marked as NotNull with parser throwing exception if empty value is passed. The check should work for any object type, not only strings. Example

var p = new FluentCommandLineParser<ApplicationArguments>();

   p.Setup(arg => arg.RecordId)
    .As('r', "record") 
    .Required(); 

   p.Setup(arg => arg.NewValue)
    .As('v', "value")
    .Required().NotNull(); // <- ensures that -v|--value is not empty

   p.Setup(arg => arg.Silent)
    .As('s', "silent")
    .SetDefault(false);

Current implementation allows command line to have ---value without any actual value so 'not null or empty' checks need be done separately.