dotnet / command-line-api

Command line parsing, invocation, and rendering of terminal output.
https://github.com/dotnet/command-line-api/wiki
MIT License
3.38k stars 381 forks source link

BinderBase functionality replacement #2358

Open barrygiles opened 6 months ago

barrygiles commented 6 months ago

I was using a BinderBase derived class in the SetHandler() function to convert several options into a complex type. Specifically, the options related to kafka configuration items and the binder returned a kafka producer.

Since the removal of BinderBase, is there any advice on how best to facilitate this type of conversion?

One of my design goals has been to segregate the command handler from anything to do with parsing. As such, there are currently no references to System.CommandLine in my command handler classes, so ideally I wouldn't simply move the conversion code there.

I also wanted to keep it separate from the definition of the command / options / arguments, which I have housed in a parser class.

The BinderBase did a nice job of helping me bridge the gap from the parser and the command handler class, and I'm not sure of the best way of replicating that in the newer version of the API (I'm using the latest nightly build).

Perhaps there isn't a way and I need to revisit my original design.

Any thoughts please @jonsequitur?

barrygiles commented 6 months ago

I suppose I could just take the logic that was in the BinderBase derived class and move it to any old class, and invoke it in the SetAction lambda to get the value, before passing it to the class responsible for doing the action...