mirror of
https://github.com/clap-rs/clap
synced 2024-12-14 14:52:33 +00:00
Merge pull request #2611 from epage/value_name
fix(derive): Follow value_name convention
This commit is contained in:
commit
3b2d23947b
3 changed files with 26 additions and 0 deletions
|
@ -791,6 +791,10 @@ impl Attrs {
|
||||||
self.name.clone().translate(*self.casing)
|
self.name.clone().translate(*self.casing)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn value_name(&self) -> TokenStream {
|
||||||
|
self.name.clone().translate(CasingStyle::ScreamingSnake)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn parser(&self) -> &Sp<Parser> {
|
pub fn parser(&self) -> &Sp<Parser> {
|
||||||
&self.parser
|
&self.parser
|
||||||
}
|
}
|
||||||
|
|
|
@ -231,6 +231,8 @@ pub fn gen_augment(
|
||||||
_ => quote!(),
|
_ => quote!(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let value_name = attrs.value_name();
|
||||||
|
|
||||||
let modifier = match **ty {
|
let modifier = match **ty {
|
||||||
Ty::Bool => quote!(),
|
Ty::Bool => quote!(),
|
||||||
|
|
||||||
|
@ -245,6 +247,7 @@ pub fn gen_augment(
|
||||||
|
|
||||||
quote_spanned! { ty.span()=>
|
quote_spanned! { ty.span()=>
|
||||||
.takes_value(true)
|
.takes_value(true)
|
||||||
|
.value_name(#value_name)
|
||||||
#possible_values
|
#possible_values
|
||||||
#validator
|
#validator
|
||||||
}
|
}
|
||||||
|
@ -252,6 +255,7 @@ pub fn gen_augment(
|
||||||
|
|
||||||
Ty::OptionOption => quote_spanned! { ty.span()=>
|
Ty::OptionOption => quote_spanned! { ty.span()=>
|
||||||
.takes_value(true)
|
.takes_value(true)
|
||||||
|
.value_name(#value_name)
|
||||||
.multiple_values(false)
|
.multiple_values(false)
|
||||||
.min_values(0)
|
.min_values(0)
|
||||||
.max_values(1)
|
.max_values(1)
|
||||||
|
@ -260,6 +264,7 @@ pub fn gen_augment(
|
||||||
|
|
||||||
Ty::OptionVec => quote_spanned! { ty.span()=>
|
Ty::OptionVec => quote_spanned! { ty.span()=>
|
||||||
.takes_value(true)
|
.takes_value(true)
|
||||||
|
.value_name(#value_name)
|
||||||
.multiple_values(true)
|
.multiple_values(true)
|
||||||
.min_values(0)
|
.min_values(0)
|
||||||
#validator
|
#validator
|
||||||
|
@ -276,6 +281,7 @@ pub fn gen_augment(
|
||||||
|
|
||||||
quote_spanned! { ty.span()=>
|
quote_spanned! { ty.span()=>
|
||||||
.takes_value(true)
|
.takes_value(true)
|
||||||
|
.value_name(#value_name)
|
||||||
.multiple_values(true)
|
.multiple_values(true)
|
||||||
#possible_values
|
#possible_values
|
||||||
#validator
|
#validator
|
||||||
|
@ -301,6 +307,7 @@ pub fn gen_augment(
|
||||||
|
|
||||||
quote_spanned! { ty.span()=>
|
quote_spanned! { ty.span()=>
|
||||||
.takes_value(true)
|
.takes_value(true)
|
||||||
|
.value_name(#value_name)
|
||||||
.required(#required)
|
.required(#required)
|
||||||
#possible_values
|
#possible_values
|
||||||
#validator
|
#validator
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
// MIT/Apache 2.0 license.
|
// MIT/Apache 2.0 license.
|
||||||
|
|
||||||
use clap::Clap;
|
use clap::Clap;
|
||||||
|
use clap::IntoApp;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn required_argument() {
|
fn required_argument() {
|
||||||
|
@ -83,3 +84,17 @@ fn arguments_safe() {
|
||||||
Opt::try_parse_from(&["test", "NOPE"]).err().unwrap().kind
|
Opt::try_parse_from(&["test", "NOPE"]).err().unwrap().kind
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn value_name() {
|
||||||
|
#[derive(Clap, PartialEq, Debug)]
|
||||||
|
struct Opt {
|
||||||
|
my_special_arg: i32,
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut help = Vec::new();
|
||||||
|
Opt::into_app().write_help(&mut help).unwrap();
|
||||||
|
let help = String::from_utf8(help).unwrap();
|
||||||
|
|
||||||
|
assert!(help.contains("MY_SPECIAL_ARG"));
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue