Skip to content

Commit 2859af0

Browse files
committed
clippy: block_in_if_condition_stmt
1 parent 2121c6b commit 2859af0

File tree

1 file changed

+31
-11
lines changed

1 file changed

+31
-11
lines changed

src/app/parser.rs

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1824,26 +1824,46 @@ impl<'a, 'b> Parser<'a, 'b>
18241824
None
18251825
}
18261826

1827+
/// Check is a given string matches the binary name for this parser
1828+
fn is_bin_name(&self, value: &str) -> bool {
1829+
self.meta.bin_name
1830+
.as_ref()
1831+
.and_then(|name| Some(value == name))
1832+
.unwrap_or(false)
1833+
}
1834+
1835+
/// Check is a given string is an alias for this parser
1836+
fn is_alias(&self, value: &str) -> bool {
1837+
self.meta.aliases
1838+
.as_ref()
1839+
.and_then(|aliases| {
1840+
for alias in aliases {
1841+
if alias.0 == value {
1842+
return Some(true);
1843+
}
1844+
}
1845+
Some(false)
1846+
})
1847+
.unwrap_or(false)
1848+
}
1849+
18271850
// Only used for completion scripts due to bin_name messiness
18281851
#[cfg_attr(feature = "lints", allow(block_in_if_condition_stmt))]
18291852
pub fn find_subcommand(&'b self, sc: &str) -> Option<&'b App<'a, 'b>> {
18301853
debugln!("Parser::find_subcommand: sc={}", sc);
18311854
debugln!("Parser::find_subcommand: Currently in Parser...{}",
18321855
self.meta.bin_name.as_ref().unwrap());
18331856
for s in self.subcommands.iter() {
1834-
if s.p.meta.bin_name.as_ref().unwrap_or(&String::new()) == sc ||
1835-
(s.p.meta.aliases.is_some() &&
1836-
s.p
1837-
.meta
1838-
.aliases
1839-
.as_ref()
1840-
.unwrap()
1841-
.iter()
1842-
.any(|&(s, _)| {
1843-
s == sc.split(' ').rev().next().expect(INTERNAL_ERROR_MSG)
1844-
})) {
1857+
if s.p.is_bin_name(sc) {
18451858
return Some(s);
18461859
}
1860+
// XXX: why do we split here?
1861+
// isn't `sc` supposed to be single word already?
1862+
let last = sc.split(' ').rev().next().expect(INTERNAL_ERROR_MSG);
1863+
if s.p.is_alias(last) {
1864+
return Some(s);
1865+
}
1866+
18471867
if let Some(app) = s.p.find_subcommand(sc) {
18481868
return Some(app);
18491869
}

0 commit comments

Comments
 (0)