This repository has been archived by the owner on Jan 1, 2022. It is now read-only.
Using index_of()/indices_of() with optional arguments that take optional values #183
Open
2 tasks done
Labels
Milestone
Issue by cptpcrd
Saturday Mar 20, 2021 at 17:21 GMT
Originally opened as clap-rs/clap#2419
Please complete the following tasks
Describe your use case
I have multiple optional arguments with optional values. If several of them were specified without passing a value, I want to determine the indices of the arguments so I can find out which one was specified first. However, it seems that this is one of the few cases where
Arg::index_of()
/Arg::indices_of()
doesn't work.A simple example can be found below.
Describe the solution you'd like
Ideally,
Arg::index_of()
would work for arguments with optional values.Alternatives, if applicable
Perhaps a new method, say
Args::index_of_opt()
(which would return the index of the flag like-a
or --all`, instead of the value) could be added?Additional Context
I'm using
structopt
, but I've translated this toclap
code.Example with clap 2.33:
This produces the following output:
Updated for clap 3 (produces the same output as the above version when run against the latest master):
The text was updated successfully, but these errors were encountered: