-
Notifications
You must be signed in to change notification settings - Fork 148
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
conflicts_with
doesn't work if the long name is not the same as the field name
#459
Comments
https://docs.rs/structopt/0.3.21/structopt/#specifying-argument-types Name is translated to kebab-case by defaullt, so the answer is: #[derive(Debug, StructOpt, Clone)]
pub struct Opts {
#[structopt(short = "n", long = "name")]
pub module_name: Option<String>,
#[structopt(short = "c", long = "cid", conflicts_with = "module-name")]
pub module_cid: Option<Cid>,
} |
Ah, I see. It would be kinda helpful with some validation for this. |
We can't really validate, as structopt doesn't know what This kebab-case thing allows to have default that are coherent with shell script conventions, but it also has its drawbacks as you pointed here. |
It can validate at runtime though? At some point it needs to check if it actually conflicts with anything and there it can presumably also see that "oh, I'm trying to check for a field that doesn't even exist". I am however not familiar with the internals of structopt so maybe this is harder than it seems. |
It would be a clap feature, structopt just generate |
This does not work. Structopt freely allows me to specify both the name and cid argument. There are no compile errors of any kind:
Neither does this:
However, this does work. Structopt correctly prevents me from using the cid and name arguments together:
This seems like a bug.
conflicts_with
should not assume that the field name is the same as the long name.Using structopt 0.3.29 with rustc 1.49.0 on ubuntu.
The text was updated successfully, but these errors were encountered: