3

I have a clap struct as follows:

#[derive(Clap)]
#[clap(
    version = "0.1.0",
    author = "..."
)]
pub struct Cli {
    #[clap(long)]
    arg_a: Option<String>,

    #[clap(long)]
    arg_b: Option<String>,

    #[clap(long)]
    arg_c: Option<String>,

    #[clap(long)]
    other_arguments: Option<usize>,
}

How do I specify that at least one of {arg_a, arg_b, arg_c} must be present, but also more can be present?

1 Answers1

0

You can read about argument relations at https://github.com/clap-rs/clap/blob/v3.1.14/examples/tutorial_derive/README.md#argument-relations

Add for example:

#[clap(group(
            ArgGroup::new("my-group")
                .required(true)
                .args(&["arg-a", "arg-b", "arg-c"]),
        ))]

https://docs.rs/clap/latest/clap/struct.ArgGroup.html#method.required "Require an argument from the group to be present when parsing."

aleb
  • 2,490
  • 1
  • 28
  • 46