I'm trying to get clap 3.2
to validate and show help correctly for the following scenario: give a token OR give username AND password.
With the current configuration I got the validation right, but the help is not very indicative of the validation.
#[derive(Parser)]
#[clap(group(
ArgGroup::new("auth")
.required(true)
.multiple(false)
.args(&["token","username"])
))]
pub struct Cli {
#[clap(long, requires = "password")]
pub username: Option<String>,
#[clap(long, requires = "username")]
pub password: Option<String>,
/// Authentication token (replaces username and password)
#[clap(long)]
pub token: Option<String>,
}
Is this the closest I can get to token OR username AND password
or there is a better way?
The current configuration falls a bit short when no option is given, that is not said that not only username is needed but the password too:
error: The following required arguments were not provided:
<--token <TOKEN>|--username <USERNAME>>
Or if only --password
is given, the same message is given.