mirror of
https://github.com/clap-rs/clap
synced 2025-03-04 15:27:16 +00:00
perf(derive): Cache positional status
This commit is contained in:
parent
7980c5ceb8
commit
efc1520223
1 changed files with 9 additions and 6 deletions
|
@ -50,6 +50,7 @@ pub struct Attrs {
|
||||||
next_help_heading: Option<Method>,
|
next_help_heading: Option<Method>,
|
||||||
help_heading: Option<Method>,
|
help_heading: Option<Method>,
|
||||||
is_enum: bool,
|
is_enum: bool,
|
||||||
|
is_positional: bool,
|
||||||
kind: Sp<Kind>,
|
kind: Sp<Kind>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -436,6 +437,7 @@ impl Attrs {
|
||||||
next_help_heading: None,
|
next_help_heading: None,
|
||||||
help_heading: None,
|
help_heading: None,
|
||||||
is_enum: false,
|
is_enum: false,
|
||||||
|
is_positional: true,
|
||||||
kind: Sp::new(Kind::Arg(Sp::new(Ty::Other, default_span)), default_span),
|
kind: Sp::new(Kind::Arg(Sp::new(Ty::Other, default_span)), default_span),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -448,6 +450,9 @@ impl Attrs {
|
||||||
} else if name == "action" {
|
} else if name == "action" {
|
||||||
self.action = Some(Action::Explicit(Method::new(name, quote!(#arg))));
|
self.action = Some(Action::Explicit(Method::new(name, quote!(#arg))));
|
||||||
} else {
|
} else {
|
||||||
|
if name == "short" || name == "long" {
|
||||||
|
self.is_positional = false;
|
||||||
|
}
|
||||||
self.methods.push(Method::new(name, quote!(#arg)));
|
self.methods.push(Method::new(name, quote!(#arg)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -810,6 +815,10 @@ impl Attrs {
|
||||||
self.is_enum
|
self.is_enum
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn is_positional(&self) -> bool {
|
||||||
|
self.is_positional
|
||||||
|
}
|
||||||
|
|
||||||
pub fn ignore_case(&self) -> TokenStream {
|
pub fn ignore_case(&self) -> TokenStream {
|
||||||
let method = self.find_method("ignore_case");
|
let method = self.find_method("ignore_case");
|
||||||
|
|
||||||
|
@ -828,12 +837,6 @@ impl Attrs {
|
||||||
self.env_casing.clone()
|
self.env_casing.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_positional(&self) -> bool {
|
|
||||||
self.methods
|
|
||||||
.iter()
|
|
||||||
.all(|m| m.name != "long" && m.name != "short")
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn has_explicit_methods(&self) -> bool {
|
pub fn has_explicit_methods(&self) -> bool {
|
||||||
self.methods
|
self.methods
|
||||||
.iter()
|
.iter()
|
||||||
|
|
Loading…
Add table
Reference in a new issue