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 85 forks source link

Custom type handling with the generic parser #83

Closed jcasale closed 7 years ago

jcasale commented 7 years ago

The generic parser does not expose a callback, how does one implement a custom handler for the assignment of a value. For example, if the container class has a field of type Encoder yet the assignment should take an integer and use Encoding.GetEncoder(int codepage), does a facility exist to perform this?

Obviously an alternative is to use an extra field and perform the assignment and validation after but that's neither clean for the developer nor informative for the user.

siywilliams commented 7 years ago

I can't give examples just yet as I'm on the road but it sounds like you need to create a parser that can handle Encoder types and add it to the CommandLineOptionFactory.

I've done this in the following test but I'm not sure if the methods are available on the interface (AddOrReplace): https://github.com/fclp/fluent-command-line-parser/blob/develop/FluentCommandLineParser.Tests/FluentCommandLineParser/when_using_an_option_factory/that_is_custom.cs

On 19 May 2017 14:35, "Joseph L. Casale" notifications@github.com wrote:

The generic parser does not expose a callback, how does one implement a custom handler for the assignment of a value. For example, if the container class has a field of type Encoder yet the assignment should take an integer and use Encoding.GetEncoder(int codepage), does a facility exist to perform this?

Obviously an alternative is to use an extra field and perform the assignment and validation after but that's neither clean for the developer nor informative for the user.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/fclp/fluent-command-line-parser/issues/83, or mute the thread https://github.com/notifications/unsubscribe-auth/ADfmmWZumj1CieQwz8NKlgipyvS_kCB6ks5r7eELgaJpZM4Ng3oH .

siywilliams commented 7 years ago

Did you manage it Joseph?

On 20 May 2017 20:08, "Joseph L. Casale" notifications@github.com wrote:

Closed #83 https://github.com/fclp/fluent-command-line-parser/issues/83.

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/fclp/fluent-command-line-parser/issues/83#event-1090690855, or mute the thread https://github.com/notifications/unsubscribe-auth/ADfmmZow97TwLCU5o-T-UvpNo2khxf8Nks5r74BpgaJpZM4Ng3oH .

jcasale commented 7 years ago

Hey Siy, I took a look, the ICommandLineOptionResult interface inherits a long list of required fields. When we replace the OptionFactory on the FluentCommandLineParser instance, does this not affect all the options?