Refactor list subcommand (#2062)
This commit is contained in:
parent
587843f09c
commit
9e658fba39
@ -38,6 +38,7 @@ pub(crate) use {
|
|||||||
use_color::UseColor, variables::Variables, verbosity::Verbosity, warning::Warning,
|
use_color::UseColor, variables::Variables, verbosity::Verbosity, warning::Warning,
|
||||||
},
|
},
|
||||||
std::{
|
std::{
|
||||||
|
borrow::Cow,
|
||||||
cmp,
|
cmp,
|
||||||
collections::{BTreeMap, BTreeSet, HashMap},
|
collections::{BTreeMap, BTreeSet, HashMap},
|
||||||
env,
|
env,
|
||||||
|
@ -505,7 +505,7 @@ impl Subcommand {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let max_line_width = cmp::min(line_widths.values().copied().max().unwrap_or(0), MAX_WIDTH);
|
let max_line_width = line_widths.values().copied().max().unwrap_or_default();
|
||||||
let doc_color = config.color.stdout().doc();
|
let doc_color = config.color.stdout().doc();
|
||||||
|
|
||||||
if level == 0 {
|
if level == 0 {
|
||||||
@ -524,28 +524,23 @@ impl Subcommand {
|
|||||||
print!(" {}", parameter.color_display(config.color.stdout()));
|
print!(" {}", parameter.color_display(config.color.stdout()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Declaring this outside of the nested loops will probably be more efficient,
|
let doc = match (i, recipe.doc) {
|
||||||
// but it creates all sorts of lifetime issues with variables inside the loops.
|
(0, Some(doc)) => Some(Cow::Borrowed(doc)),
|
||||||
// If this is inlined like the docs say, it shouldn't make any difference.
|
(0, None) => None,
|
||||||
let print_doc = |doc| {
|
_ => Some(Cow::Owned(format!("alias for `{}`", recipe.name))),
|
||||||
|
};
|
||||||
|
|
||||||
|
if let Some(doc) = doc {
|
||||||
print!(
|
print!(
|
||||||
" {:padding$}{} {}",
|
" {:padding$}{} {}",
|
||||||
"",
|
"",
|
||||||
doc_color.paint("#"),
|
doc_color.paint("#"),
|
||||||
doc_color.paint(doc),
|
doc_color.paint(&doc),
|
||||||
padding = max_line_width
|
padding = max_line_width
|
||||||
.saturating_sub(line_widths.get(name).copied().unwrap_or(max_line_width))
|
.saturating_sub(line_widths.get(name).copied().unwrap_or(max_line_width))
|
||||||
);
|
);
|
||||||
};
|
}
|
||||||
|
|
||||||
match (i, recipe.doc) {
|
|
||||||
(0, Some(doc)) => print_doc(doc),
|
|
||||||
(0, None) => (),
|
|
||||||
_ => {
|
|
||||||
let alias_doc = format!("alias for `{}`", recipe.name);
|
|
||||||
print_doc(&alias_doc);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
println!();
|
println!();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user