Multiple positionals with multiple values #5463
Unanswered
superstator
asked this question in
Q&A
Replies: 1 comment 1 reply
-
The asserts and parser have likely not been hardened against accepting a fixed Feel free to open an issue about this. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I want to build a CLI in Rust, using
clap
, which can accept some number of positional arguments with a set number of values each, and a final argument accepting whatever positional values were left over. For example,./app a b c
with a positional argument accepting 2 values, and a positional argument accepting leftovers, would assigna b
to the first arg, andc
to the second. I'm able to do this with a positional argument that accepts a single value:But if I try to have the first arg accept two values like this:
I get the error
Positional argument [TWO]... *must* have required(true) or last(true) set because a prior positional argument ([ONE] [ONE]) has num_args(1..)
. If I make argumentTWO
required, I just get a different error, and if I make them both required the last argument is always attached toTWO
, making it impossible to accept something like./app a b
or./app a b c d
and still haveONE
capture the first two values.The only thing I've found that gets me the functionality I want is to have a single generic positional argument with
.action(ArgAction::Append)
and then carve up those matches myself, but then I lose out on the helpful help messagesclap
would otherwise generate. Is there another way?Beta Was this translation helpful? Give feedback.
All reactions