rust
cli_error
ai_generated
true
error: The argument '--flag-a' cannot be used with '--flag-b'
ID: rust/rust-clap-argument-conflict
90%Fix Rate
92%Confidence
50Evidence
2023-01-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 1 | active | — | — | — |
Root Cause
Clap's argument conflicts_with configuration prevents mutually exclusive flags from being used together.
genericWorkarounds
-
90% success Use ArgGroup to define mutually exclusive argument groups
use clap::{Arg, ArgGroup, Command}; Command::new("app") .group(ArgGroup::new("mode") .args(["verbose", "quiet"]) .required(false))Sources: https://docs.rs/clap/latest/clap/struct.ArgGroup.html
-
88% success Use clap derive with group attribute for clean conflict declaration
#[derive(Parser)] struct Cli { #[arg(long, group = "verbosity")] verbose: bool, #[arg(long, group = "verbosity")] quiet: bool, }Sources: https://docs.rs/clap/latest/clap/_derive/index.html
Dead Ends
Common approaches that don't work:
-
Remove all conflicts_with rules to allow any combination
65% fail
The conflicts exist for a reason; allowing incompatible flags causes logic errors
Error Chain
Preceded by:
Frequently confused with: