This is actually a summary of TeXitoi/structopt#364
Current behavior
Vec<T> and Option<Vec<T>> are not required = true by default.
Vec<T> is multiple = true by default which allows not only multiple values (--foo 1 2 3) but also multiple occurrences (--foo 1 --foo 2 3).
Option<Vec<T>> additionally allows zero number of values (--foo).
What's wrong
- The fact that
Vec<T> is not required by default is inconsistent with all the other types in clap_derive that are required by default unless they are wrapped in Option (except bool but it's a very special case).
- The fact that
Option<Vec<T>> is different from Vec<T>, different not in "not required" sense, confuses newcomers.
- The fact that
Vec<T> allows multiple occurrences along with values is misleading.
Proposal
- Use
min_values = 1 for both Option<Vec<T>> and Vec<T> instead of multiple = true, allowing only non-zero number of values and disallow multiple occurrences (--foo 1 2 but not --foo nor --foo 1 --foo 2). If a user wants to allow zero values or multiple occurrences as well, they can explicitly specify it via min_values = 0 and multiple = true respectively.
- Use
required = true for Vec<T>.
cc @TeXitoi @Dylan-DPC @pksunkara
This is actually a summary of TeXitoi/structopt#364
Current behavior
Vec<T>andOption<Vec<T>>are notrequired = trueby default.Vec<T>ismultiple = trueby default which allows not only multiple values (--foo 1 2 3) but also multiple occurrences (--foo 1 --foo 2 3).Option<Vec<T>>additionally allows zero number of values (--foo).What's wrong
Vec<T>is notrequiredby default is inconsistent with all the other types inclap_derivethat are required by default unless they are wrapped inOption(exceptboolbut it's a very special case).Option<Vec<T>>is different fromVec<T>, different not in "not required" sense, confuses newcomers.Vec<T>allows multiple occurrences along with values is misleading.Proposal
min_values = 1for bothOption<Vec<T>>andVec<T>instead ofmultiple = true, allowing only non-zero number of values and disallow multiple occurrences (--foo 1 2but not--foonor--foo 1 --foo 2). If a user wants to allow zero values or multiple occurrences as well, they can explicitly specify it viamin_values = 0andmultiple = truerespectively.required = trueforVec<T>.cc @TeXitoi @Dylan-DPC @pksunkara