How to return an error when the value of another argument is unexpected #5556
Answered
by
epage
sorairolake
asked this question in
Q&A
-
Hi, I want to return an error if an argument is specified, but the value of another argument is unexpected. # OK
$ cmd --http2
$ cmd --http3
$ cmd --http3 --http3-only
# Error
$ cmd --http3-only
$ cmd --http2 --http3-only #[derive(Debug, Parser)]
#[command(version, about)]
pub struct Opt {
#[arg(long, conflicts_with("http3"))]
pub http2: bool,
#[arg(long)]
pub http3: bool,
#[arg(long, requires("http3"))]
pub http3_only: bool,
} How can I make the following example work like the above? # OK
$ cmd --http-version=2
$ cmd --http-version=3
$ cmd --http-version=3 --http3-only
# Error
$ cmd --http3-only
$ cmd --http-version=2 --http3-only #[derive(Debug, Parser)]
#[command(version, about)]
pub struct Opt {
#[arg(long, value_enum)]
pub http_version: HttpVersion,
// How can I change the following attributes?
#[arg(long)]
pub http3_only: bool,
}
#[derive(Clone, Debug, ValueEnum)]
pub enum HttpVersion {
#[clap(name = "2")]
Http2,
#[clap(name = "3")]
Http3,
} |
Beta Was this translation helpful? Give feedback.
Answered by
epage
Jun 27, 2024
Replies: 1 comment
-
We do not support this at this time and it would require having a check in your application after parsing. |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
sorairolake
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
We do not support this at this time and it would require having a check in your application after parsing.
We have requires_if but it is the opposite of what you want.