-
Notifications
You must be signed in to change notification settings - Fork 86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for a minimum number of repeated arguments #110
Comments
Implementation-wise, this seems like it could be added to |
I am not too familiar with writing proc macros, but I arrived here having just run into a need for this feature, and I have an idea for the syntax wrt your Proposal 2 — Range syntax. Like so:
Assuming the supported syntax is roughly similar to standard Macros, I could see this being done with a special case for a Literal, and then a fallback case which takes whatever |
I would not complicate so much the space of possibilities. My view is the following. At the moment there is a My proposal would be to start distinguishing them, as follows:
Then, The problem is that this is a breaking change, it is not backwards compatible. However, I find it more natural to think of "optionality" in terms of Let me know your thoughts. Edit: this approach is based on the presumption that a |
To @alexonea's proposal, I would add two things.
optionality = if let Some(x) = ty_inner(&["Option"], &field.ty) {
Optionality::Optional
} else if let Some(x) = ty_inner(&["Vec"], &field.ty) {
Optionality::Repeating
} else {
Optionality::None
}; However, in my view, the problem here is that the second branch creates a rule that supersedes the first one, and it shouldn't. I strongly believe that in a command-line context linking required and empty makes no sense. Therefore, accepting an empty It is either required and has at least one element, or it is optional but then it is marked accordingly ( |
Whether
positional
oroption
arguments that are of typeVec<T>
are always treated as "0 or more", with no way to specify "one or more", or "two or more".This is similar to issue #13, but a more general case.
I can make two proposals here:
Proposal 1:
add an attribute such as
#[argh(option, required)]
, which forces some value to be present for vec-types.Proposal 2:
add an attribute such as
#[argh(option, required(2+)]
or#[argh(option, required="2+")]
Help text would need to be adjusted accordingly as well, such as:
The text was updated successfully, but these errors were encountered: