-
Notifications
You must be signed in to change notification settings - Fork 152
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
Groups within subcommands not working as expected #151
Comments
I have to inverstigate a bit, but I think that's a clap bug. I'll try to reproduce it in pure clap when I have the time. |
I do have a similar bug to report. use structopt::{clap::ArgGroup, StructOpt};
#[derive(StructOpt, Debug)]
#[structopt(group = ArgGroup::with_name("verb").required(true).multiple(true))]
struct Opt {
#[structopt(long, group = "verb")] foo: bool,
#[structopt(long, group = "verb")] bar: bool,
}
pub fn main() {
Opt::from_args();
} It reports an error when none of #[derive(Debug, StructOpt)]
struct Cli {
#[structopt(flatten)]
a: Opt
}
pub fn main() {
Cli::from_args();
} It doesn't fail when none of |
I gave a bit of investigation and there's a working variant: use structopt::{clap::ArgGroup, StructOpt};
#[derive(StructOpt, Debug)]
struct Opt {
#[structopt(long, group = "verb")] foo: bool,
#[structopt(long, group = "verb")] bar: bool,
}
#[derive(Debug, StructOpt)]
#[structopt(group = ArgGroup::with_name("verb").required(true).multiple(true))]
struct Cli {
#[structopt(flatten)]
a: Opt
}
pub fn main() {
Cli::from_args();
} I.e you must put I'm not sure whether it's a bug or intentional behavior, I need to take a closer look at the machinery. I promise I'll get to it by the end of the week even if I'll have to fake my death to my boss (I know you're reading this, you bastard). Also could someone kindly lend me a time machine? |
OK, it turns out that We cannot make this work, I don't think so. It would require an access to internal I suggest to simply document this pitfall. |
@CreepySkeleton So the sole workaround is to move this invocation #[structopt(group = ArgGroup::with_name("verb").required(true).multiple(true))] to the struct arg group is flattened to, isn't it? |
@Veetaha Yes. More specifically, all "top level" Good news: I managed to fix it! And the fix is ridiculously simple! Will be released in the next patch, few days from now. |
@CreepySkeleton Great news, thank you! |
I am trying to get a program with subcommands, one of which requires at least one flag. So, for example, I would want the following behavior:
cargo run -- a
failscargo run -- a -c
succeedscargo run -- a -d
succeedscargo run -- a -cd
succeedsI can get it working using a
clap::ArgGroup
without subcommands, but not with subcommands.For example, given the following
this works (though not as a subcommand)
but this does not
Instead, I get the following behavior:
cargo run -- a
failscargo run -- a -c
succeedscargo run -- a -d
succeedscargo run -- a -cd
failsSo I'm not sure if I'm doing something wrong or if perhaps its a bug in structopt.
I'm using structopt 0.2.13 and rust nightly (6acbb5b65 2018-11-25).
The text was updated successfully, but these errors were encountered: