Skip to content

Commit

Permalink
perf(help): Remove more from usage feature
Browse files Browse the repository at this point in the history
Quality of error-context goes down with this.
  • Loading branch information
epage committed Sep 19, 2022
1 parent b13ec5c commit aecef54
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
2 changes: 0 additions & 2 deletions src/output/usage.rs
Expand Up @@ -312,9 +312,7 @@ impl<'cmd> Usage<'cmd> {
debug!("Usage::get_args: ret_val={:?}", ret_val);
ret_val
}
}

impl<'cmd> Usage<'cmd> {
pub(crate) fn get_required_usage_from(
&self,
incls: &[Id],
Expand Down
31 changes: 26 additions & 5 deletions src/parser/validator.rs
Expand Up @@ -401,11 +401,32 @@ impl<'cmd> Validator<'cmd> {

let usg = Usage::new(self.cmd).required(&self.required);

let req_args = usg
.get_required_usage_from(&raw_req_args, Some(matcher), true)
.into_iter()
.map(|s| s.to_string())
.collect::<Vec<_>>();
let req_args = {
#[cfg(feature = "usage")]
{
usg.get_required_usage_from(&raw_req_args, Some(matcher), true)
.into_iter()
.map(|s| s.to_string())
.collect::<Vec<_>>()
}

#[cfg(not(feature = "usage"))]
{
raw_req_args
.iter()
.map(|id| {
if let Some(arg) = self.cmd.find(id) {
arg.to_string()
} else if let Some(_group) = self.cmd.find_group(id) {
self.cmd.format_group(id).to_string()
} else {
debug_assert!(false, "id={:?} is unknown", id);
"".to_owned()
}
})
.collect::<Vec<_>>()
}
};

debug!(
"Validator::missing_required_error: req_args={:#?}",
Expand Down

0 comments on commit aecef54

Please sign in to comment.