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 fails
cargo run -- a -c succeeds
cargo run -- a -d succeeds
cargo run -- a -cd succeeds
I can get it working using a clap::ArgGroup without subcommands, but not with subcommands.
For example, given the following
use structopt::clap::ArgGroup;
use structopt::StructOpt;
fn arg_group() -> ArgGroup<'static> {
ArgGroup::with_name("group").required(true).multiple(true)
}
#[derive(StructOpt, Debug)]
#[structopt(raw(group = "arg_group()"))]
struct Sub {
#[structopt(short = "c", group = "group")]
c: bool,
#[structopt(short = "d", group = "group")]
d: bool,
}
#[derive(StructOpt, Debug)]
enum Opt {
#[structopt(name = "a", raw(group = "arg_group()"))]
A (Sub),
#[structopt(name = "b")]
B {},
}
this works (though not as a subcommand)
fn main() {
let opt = Sub::from_args();
println!("{:?}", opt);
}
but this does not
fn main() {
let opt = Opt::from_args();
println!("{:?}", opt);
}
Instead, I get the following behavior:
cargo run -- a fails
cargo run -- a -c succeeds
cargo run -- a -d succeeds
cargo run -- a -cd fails
So 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).
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 -- afailscargo run -- a -csucceedscargo run -- a -dsucceedscargo run -- a -cdsucceedsI can get it working using a
clap::ArgGroupwithout 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 -- afailscargo run -- a -csucceedscargo run -- a -dsucceedscargo run -- a -cdfailsSo 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).