Validate a list of numbers with a custom validator
Hi,
I wondered if something like this is possible; let's say I have an optional argument -f,--freqs that receives two integer values -f 10 20. I want to check a simple property on the input values. For instance, L>R/2, where L is the left integer and R is the right. I tried to make a custom validator for this task, but the default behavior of CLI11 is to check the elements independently (i.e., in my example, 10 is checked separately from 20).
What can I do?
BTW, thanks for your library; very useful.
I think the only behavior is to validate the arguments 1 at a time, so no changing that nor do I think it would be practical to do so.
However, Validators have a property application_index which can selectively apply validators to a specific element of the sequence, and they are applied in element order. So the best solution is then to define 2 Validators. The first with application_index(0) simply stores a value in a memory location accessible to both validators, the second with application_index(1) actually does the check using the value stored from the first one as well as the value being validated.
There are likely other ways of accomplishing the same thing but that is how I would do it.
OK, thanks. I will try your solution.
Hi I have similar problem but i would like to check the count of elements in user passed list e.g. I have option -x that takes a list of arguments a0 a1 a2 ..., but I would like to restrict that max count of arguments for this option is 10. I tried to write custom validator but it can validate only one element at the time.