mirror of
https://github.com/clap-rs/clap
synced 2025-03-04 23:37:32 +00:00
refactor(help): Clean up code
This commit is contained in:
parent
a666328c1f
commit
2b4541fab2
2 changed files with 14 additions and 5 deletions
|
@ -353,14 +353,13 @@ impl<'cmd> Usage<'cmd> {
|
|||
incls: &[Id],
|
||||
matcher: Option<&ArgMatcher>,
|
||||
incl_last: bool,
|
||||
) -> FlatSet<StyledStr> {
|
||||
) -> Vec<StyledStr> {
|
||||
debug!(
|
||||
"Usage::get_required_usage_from: incls={:?}, matcher={:?}, incl_last={:?}",
|
||||
incls,
|
||||
matcher.is_some(),
|
||||
incl_last
|
||||
);
|
||||
let mut ret_val = FlatSet::new();
|
||||
|
||||
let mut unrolled_reqs = FlatSet::new();
|
||||
|
||||
|
@ -405,7 +404,7 @@ impl<'cmd> Usage<'cmd> {
|
|||
let mut required_groups_members = FlatSet::new();
|
||||
let mut required_opts = FlatSet::new();
|
||||
let mut required_groups = FlatSet::new();
|
||||
let mut required_positionals = Vec::new();
|
||||
let mut required_positionals = FlatSet::new();
|
||||
for req in unrolled_reqs.iter().chain(incls.iter()) {
|
||||
if let Some(arg) = self.cmd.find(req) {
|
||||
let is_present = matcher
|
||||
|
@ -418,7 +417,7 @@ impl<'cmd> Usage<'cmd> {
|
|||
if !is_present {
|
||||
if arg.is_positional() {
|
||||
if incl_last || !arg.is_last_set() {
|
||||
required_positionals.push((arg.index.unwrap(), arg.stylized()));
|
||||
required_positionals.insert((arg.index.unwrap(), arg.stylized()));
|
||||
}
|
||||
} else {
|
||||
required_opts.insert(arg.stylized());
|
||||
|
@ -451,6 +450,8 @@ impl<'cmd> Usage<'cmd> {
|
|||
}
|
||||
}
|
||||
|
||||
let mut ret_val = Vec::new();
|
||||
|
||||
required_opts.retain(|arg| !required_groups_members.contains(arg));
|
||||
ret_val.extend(required_opts);
|
||||
|
||||
|
@ -459,7 +460,7 @@ impl<'cmd> Usage<'cmd> {
|
|||
required_positionals.sort_by_key(|(ind, _)| *ind); // sort by index
|
||||
for (_, p) in required_positionals {
|
||||
if !required_groups_members.contains(&p) {
|
||||
ret_val.insert(p);
|
||||
ret_val.push(p);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -50,6 +50,14 @@ impl<T: PartialEq + Eq> FlatSet<T> {
|
|||
pub(crate) fn iter(&self) -> std::slice::Iter<'_, T> {
|
||||
self.inner.iter()
|
||||
}
|
||||
|
||||
pub fn sort_by_key<K, F>(&mut self, f: F)
|
||||
where
|
||||
F: FnMut(&T) -> K,
|
||||
K: Ord,
|
||||
{
|
||||
self.inner.sort_by_key(f);
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: PartialEq + Eq> Default for FlatSet<T> {
|
||||
|
|
Loading…
Add table
Reference in a new issue