Replies: 2 comments
-
Given the Spectre.Console.Cli functionality, i would stick with a string array option and then do the conversion into a Your struggles with the type converter not withstanding, I would not recommend using a type converter via the On the other hand, exceptions thrown in the Validate method will result in a user-facing error with the exception message. Even better, the Validate method allows you to produce a user-facing error message without needing to rely on exceptions to carry user-facing errors (as shown in the example here). |
Beta Was this translation helpful? Give feedback.
-
Thanks! I'll play around with it. Your response is greatly appreciated. |
Beta Was this translation helpful? Give feedback.
-
I'm looking for advice on the best way to bind multiple input from the command line into a single object.
I have a fairly complex object. Instead of passing in values for the object directly through the command line, I want to be able to pass in the location to one or more yaml files containing the object.
I have implemented this as follows.
This works exactly as desired when I pass in a single file, eg
my-cli --meta file-1.yaml
.However, when I pass in multiple files, eg
my-cli --meta file-1.yaml --meta file-2.yaml
, theConvertFrom
method is invoked twice, and only the value of the second iteration is being kept.I can get around this by making the converter stateful like below, but I am noticing that a single
TypeConverter<T>
instance is being re-used for all conversions.For example, if I alter the settings to have more than one property using the same type converter, and then run
my-cli --meta file-1.yaml --meta file-2.yaml --meta2 file-3.yaml
, because the above converter is stateful, all 3 files are being merged together.Is there a better way to achieve this? Instead of using
<VALUES>
, should I accept a single delimited list of file paths, and do the parsing myself? Ideally, I would like to avoid any sort of correctness requirements based on the statefulness of the type converter.Beta Was this translation helpful? Give feedback.
All reactions