-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
name
implies a user-facing meaning, causing confusion
#3335
Comments
conflicts_with
on a flag does not work when conflicting with a positional argconflicts_with
on a flag panics when conflicting with a positional arg
use clap::Parser;
#[derive(Debug, Parser)]
pub struct Example {
#[clap(short = 'S', long, conflicts_with = "version")]
pub staged: bool,
#[clap(name = "OBJ_ID")]
pub object_id: String,
#[clap(name = "VERSION")]
pub version: Option<String>,
}
fn main() {
println!("{:?}", Example::parse());
} should be use clap::Parser;
#[derive(Debug, Parser)]
pub struct Example {
#[clap(short = 'S', long, conflicts_with = "VERSION")]
pub staged: bool,
#[clap(name = "OBJ_ID")]
pub object_id: String,
#[clap(name = "VERSION")]
pub version: Option<String>,
}
fn main() {
println!("{:?}", Example::parse());
} With Most likely what you want is use clap::Parser;
#[derive(Debug, Parser)]
pub struct Example {
#[clap(short = 'S', long, conflicts_with = "version")]
pub staged: bool,
#[clap(value_name = "OBJ_ID")]
pub object_id: String,
#[clap(value_name = "VERSION")]
pub version: Option<String>,
}
fn main() {
println!("{:?}", Example::parse());
} This kind of confusion is why I want to rename it from |
😊 Thank you! You are correct that I was confusing |
conflicts_with
on a flag panics when conflicting with a positional argname
implies a user-facing meaning, causing confusion
Keeping this open as a use case for why we should explore changing |
For what it's worth, I experienced the issue because I migrated from clap 2 + structopt, and structopt includes an example like the following in its docs:
I looked at the docs for clap 3, and I do think it's clear what |
This adjusts names. Adjusting the derive naming (and re-naming) is left to clap-rs#2475. Fixes clap-rs#3335
Maintainer's notes:
name
vsvalue_name
and impact on the rest of the APIArg::name
toArg::id
value_name
on people's behalf.Please complete the following tasks
Rust Version
rustc 1.58.1 (db9d1b20b 2022-01-20)
Clap Version
3.0.10
Minimal reproducible code
Steps to reproduce the bug with the above code
Actual Behaviour
Panics:
Expected Behaviour
It should not panic. I would expect Clap to enforce that the
staged
flag cannot be set if aversion
positional arg is provided, and otherwise allow the flag to be present or not.Additional Context
conflicts_with
works as expected when conflicting with another flag. The problem seems to be when conflicting with an optional positional arg.Debug Output
The text was updated successfully, but these errors were encountered: