gsscoder/commandline

How to set Option with the requirement to have exact two values?

dasdingo opened this issue · 6 comments

I want to create an Option where at least two values are required but I don't find an attribute like that. Is there a way to define such a requirement? Example: --openSheet [path] [table]

You could use the [OptionArray] attribute in a fashion similar to the following example (see code sample below); maybe in your case you would rather use string[].

[OptionArray('v', "values", DefaultValue = new double[] {.1, .2, .3})]
public double[] Temperatures { get; set; }

:0)

hmmm, after giving some more thinking time to your question, maybe the following example is a better fit to your reqs:

[ValueList(typeof(List), MaximumElements = 2)]
public IList OtherStuff { get; set; }

;0)

nemec commented

Are you using the 2.0 beta? You should be able to use the Option("openSheet", Min=2) syntax to set the minimum number of values.

I switched to version 2.0.0.0, but when using the Min and Max properties it seems that the validator doesnt check for the amount of values. So it is not possible for me to trigger a parse issue when having less than 3 values. Example:" --command a b"->result is still valid

[Option('c', "command", Min = 3,Max = 3, HelpText = "Command desc.")]
public IEnumerable Commands { get; set; }

I just played around with the amounts of parameter and I could see that the "Min" requirement is working, but the "Max" requirement is ignored.

I used version 2.0.0.0 before. Now I am using 2.0.275.0 and everything works fine! Thank you very much!