mirror of
https://github.com/clap-rs/clap
synced 2024-12-13 22:32:33 +00:00
refactor: implements PartialEq for some of the base structs
This commit is contained in:
parent
c53e273c7c
commit
96884aa1b2
7 changed files with 38 additions and 8 deletions
|
@ -1168,13 +1168,12 @@ impl<'a, 'b> Parser<'a, 'b>
|
|||
args.extend(self.arg_names_in_group(n));
|
||||
g_vec.push(*n);
|
||||
} else {
|
||||
if !args.contains(n) {
|
||||
args.push(*n);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: faster way to sort/dedup?
|
||||
args.sort();
|
||||
args.dedup();
|
||||
args.iter().map(|s| *s).collect()
|
||||
}
|
||||
|
||||
|
|
|
@ -421,13 +421,14 @@ pub fn get_required_usage_from<'a, 'b>(p: &Parser<'a, 'b>,
|
|||
});
|
||||
ret_val.push_back(arg);
|
||||
}
|
||||
let mut g_vec = vec![];
|
||||
let mut g_vec: Vec<String> = vec![];
|
||||
for g in desc_reqs.iter().filter(|n| p.groups.iter().any(|g| &&g.name == n)) {
|
||||
let g_string = p.args_in_group(g).join("|");
|
||||
g_vec.push(format!("<{}>", &g_string[..g_string.len()]));
|
||||
let elem = format!("<{}>", &g_string[..g_string.len()]);
|
||||
if !g_vec.contains(&elem) {
|
||||
g_vec.push(elem);
|
||||
}
|
||||
}
|
||||
g_vec.sort();
|
||||
g_vec.dedup();
|
||||
for g in g_vec {
|
||||
ret_val.push_back(g);
|
||||
}
|
||||
|
|
|
@ -3327,3 +3327,9 @@ impl<'a, 'b, 'z> From<&'z Arg<'a, 'b>> for Arg<'a, 'b> {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'n, 'e> PartialEq for Arg<'n, 'e> {
|
||||
fn eq(&self, other: &Arg<'n, 'e>) -> bool {
|
||||
self.b == other.b
|
||||
}
|
||||
}
|
|
@ -26,3 +26,9 @@ impl<'n, 'e> Base<'n, 'e> {
|
|||
impl<'n, 'e, 'z> From<&'z Arg<'n, 'e>> for Base<'n, 'e> {
|
||||
fn from(a: &'z Arg<'n, 'e>) -> Self { a.b.clone() }
|
||||
}
|
||||
|
||||
impl<'n, 'e> PartialEq for Base<'n, 'e> {
|
||||
fn eq(&self, other: &Base<'n, 'e>) -> bool {
|
||||
self.name == other.name
|
||||
}
|
||||
}
|
|
@ -105,6 +105,12 @@ impl<'n, 'e> DispOrder for FlagBuilder<'n, 'e> {
|
|||
fn disp_ord(&self) -> usize { self.s.disp_ord }
|
||||
}
|
||||
|
||||
impl<'n, 'e> PartialEq for FlagBuilder<'n, 'e> {
|
||||
fn eq(&self, other: &FlagBuilder<'n, 'e>) -> bool {
|
||||
self.b == other.b
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use args::settings::ArgSettings;
|
||||
|
|
|
@ -149,6 +149,12 @@ impl<'n, 'e> DispOrder for OptBuilder<'n, 'e> {
|
|||
fn disp_ord(&self) -> usize { self.s.disp_ord }
|
||||
}
|
||||
|
||||
impl<'n, 'e> PartialEq for OptBuilder<'n, 'e> {
|
||||
fn eq(&self, other: &OptBuilder<'n, 'e>) -> bool {
|
||||
self.b == other.b
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use args::settings::ArgSettings;
|
||||
|
|
|
@ -138,6 +138,12 @@ impl<'n, 'e> DispOrder for PosBuilder<'n, 'e> {
|
|||
fn disp_ord(&self) -> usize { self.index as usize }
|
||||
}
|
||||
|
||||
impl<'n, 'e> PartialEq for PosBuilder<'n, 'e> {
|
||||
fn eq(&self, other: &PosBuilder<'n, 'e>) -> bool {
|
||||
self.b == other.b
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use args::settings::ArgSettings;
|
||||
|
|
Loading…
Reference in a new issue