fclp / fluent-command-line-parser

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

Another validation question #35

Open ghost opened 9 years ago

ghost commented 9 years ago

I've written a validation extension method using ICommandLineOptionFluent as the extensions key parameter, the method signature is as follows:

    public static void Validate<T>(this ICommandLineOptionFluent<T> value, Predicate<T> validate)
    {
        ...
        ...
        ...
    }

My question is how can I get the value to pass to the predicate, currently I see no way of doing this rendering the extension pointless. I was hoping to write something which I could contribute back.

As as an example of how I pictured this working:

        fluentCommandLineParser
            .Setup(arg => arg.Endpoints)
            .As('e', "endpoint")
            .Required()
            .Validate(addresses => addresses.All(address => address.IsAddress()));

Any advice?

Thanks, Lee.

siywilliams commented 9 years ago

Hi Lee,

You're unfortunately not going to get access to the guts that you want through the use of extensions methods, you'll have to mod the library itself.

I've just whipped up a rough commit with the bits that I think you would need. See the commit I've made in the new Issue-35 branch

I'm thinking the validation errors would be returned the same way as when values are unable to be parsed i.e through the result.Errors property.