TeXitoi / structopt

Parse command line arguments by defining a struct.
Other
2.7k stars 149 forks source link

Support conflicts_with with flattened field. #526

Open ababo opened 2 years ago

ababo commented 2 years ago

I would like to have an ability to do something like this:

    #[structopt(long, conflicts_with = "bar")]
    pub foo: bool,

    #[structopt(flatten)]
    pub bar: BarParams,

This means that if foo flag is set no flag from bar can be used.

epage commented 2 years ago

As a heads up, structopt is in maintenance mode at this point and new development is happening in clap.

As for this specific request, this falls into a derive-implementation challenge. This requires some form of cross-struct communication. As immediately presented, we'd need a way to apply the bar group name to all of BarParams fields. Say we instead have BarParams implicitly create a group named BarParams. The challenge there is then with if the user does a flatten within BarParams, we'd need to recursively apply the group name which goes back to that first problem