I am trying to use structopt/clap to parse the arguments of a CLI which supports the two following invocations:
# Accept a single file and a list of labels
$ my_cli FILE LABEL...
# Accept a list of files
$ my_cli --labels="label1 label2" FILE ...
With structopt, I would normally store the files in a Vec<PathBuf>
and the labels in a Vec<Label>
. Unfortunately, having two vectors as positional arguments is ambiguous, and Clap panics with:
When using a positional argument with .multiple(true) that is *not the last* positional argument,
the last positional argument (i.e the one with the highest index) *must* have .required(true)
or .last(true) set.
I would like to tell Clap somehow that the two Vec will never occur at the same time. Using conflicts_with()
and friends does not help. I thought I could use an ArgGroup
for each alternative, but this doesn't seem to work either (please let me know if I missed something here).
I suppose I could have a single Vec<String>
and reuse it for both files and labels, but this would mean more manual work to convert to the proper types, and it would mess with the help message. Is there a better way to do this kind of thing?