mirror of
https://github.com/clap-rs/clap
synced 2024-11-10 14:54:15 +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>,
|
||||
help_heading: Option<Method>,
|
||||
is_enum: bool,
|
||||
is_positional: bool,
|
||||
kind: Sp<Kind>,
|
||||
}
|
||||
|
||||
|
@ -436,6 +437,7 @@ impl Attrs {
|
|||
next_help_heading: None,
|
||||
help_heading: None,
|
||||
is_enum: false,
|
||||
is_positional: true,
|
||||
kind: Sp::new(Kind::Arg(Sp::new(Ty::Other, default_span)), default_span),
|
||||
}
|
||||
}
|
||||
|
@ -448,6 +450,9 @@ impl Attrs {
|
|||
} else if name == "action" {
|
||||
self.action = Some(Action::Explicit(Method::new(name, quote!(#arg))));
|
||||
} else {
|
||||
if name == "short" || name == "long" {
|
||||
self.is_positional = false;
|
||||
}
|
||||
self.methods.push(Method::new(name, quote!(#arg)));
|
||||
}
|
||||
}
|
||||
|
@ -810,6 +815,10 @@ impl Attrs {
|
|||
self.is_enum
|
||||
}
|
||||
|
||||
pub fn is_positional(&self) -> bool {
|
||||
self.is_positional
|
||||
}
|
||||
|
||||
pub fn ignore_case(&self) -> TokenStream {
|
||||
let method = self.find_method("ignore_case");
|
||||
|
||||
|
@ -828,12 +837,6 @@ impl Attrs {
|
|||
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 {
|
||||
self.methods
|
||||
.iter()
|
||||
|
|
Loading…
Reference in a new issue