New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Validate conflicts_with
#2307
Comments
Have you checked this with master? And also please provide a minimal sample code so it's easier for everyone. |
I have not yet, my testing was done with clap v2.33.3 which is the latest stable version afaik (though I see that there's a 3.0 beta now). I use structopt so that generates most of the code for me. You can find an example of that in the linked issue. Here is the code that structopt generates which corresponds to this issue: let app = app.about("Runs a module");
let app = app.arg(
::structopt::clap::Arg::with_name("module-name")
.takes_value(true)
.multiple(false)
.validator(|s| {
::std::str::FromStr::from_str(s.as_str())
.map(|_: String| ())
.map_err(|e| e.to_string())
})
.help("Name of the cmdlet module to run")
.short("n")
.long("name"),
);
let app = app.arg(
::structopt::clap::Arg::with_name("module-cid")
.takes_value(true)
.multiple(false)
.validator(|s| {
::std::str::FromStr::from_str(s.as_str())
.map(|_: Cid| ())
.map_err(|e| e.to_string())
})
.help("CID of the cmdlet module to run")
.short("c")
.long("cid")
.conflicts_with("module_name"),
);
app.version("0.1.0") Note that |
Can you please test it on clap master and report back? |
Hi I can confirm that this still happens with master. [dependencies]
clap = { git = "https://github.com/clap-rs/clap.git", rev= "d7f6748" } use clap::{App, Arg};
fn main() {
let app = App::new("My Super Program")
.about("Runs a module")
.arg(
Arg::new("module-name")
.takes_value(true)
.multiple(false)
.short('n')
.long("name"),
)
.arg(
Arg::new("module-cid")
.takes_value(true)
.multiple(false)
.short('c')
.long("cid")
.conflicts_with("module_name"),
)
.version("0.1.0");
let matches = app.get_matches();
println!("{:#?}", matches);
}
|
This has since been resolved We have an existing test #[cfg(debug_assertions)]
#[test]
#[should_panic]
fn non_existent_conflict_asserts() {
App::new("My Super Program")
.about("Runs a module")
.arg(
Arg::new("module-name")
.takes_value(true)
.multiple(false)
.short('n')
.long("name"),
)
.arg(
Arg::new("module-cid")
.takes_value(true)
.multiple(false)
.short('c')
.long("cid")
.conflicts_with("module_name"),
)
.version("0.1.0")
.debug_assert();
} And it passes on 3.0.0-rc.4 |
Make sure you completed the following tasks
Describe your use case
Currently, it can sometimes be tricky to know which name to give to
conflicts_with
, in particular in combination withstructopt
.Take a look at this issue for context: TeXitoi/structopt#459
Clap currently doesn't seem to care if
conflicts_with
is given a name which isn't even a valid field.Describe the solution you'd like
Clap validates that the field
conflicts_with
is given actually exists.The text was updated successfully, but these errors were encountered: