fix(help): Make next-line help less sensitive to tab changes

This commit is contained in:
Ed Page 2022-09-07 15:52:26 -05:00
parent d3fc37b678
commit 876da97d1c

View file

@ -547,11 +547,13 @@ impl<'cmd, 'writer> Help<'cmd, 'writer> {
// Is help on next line, if so then indent // Is help on next line, if so then indent
if next_line_help { if next_line_help {
debug!("Help::help: Next Line...{:?}", next_line_help); debug!("Help::help: Next Line...{:?}", next_line_help);
self.none(format!("\n{}{}{}", TAB, TAB, TAB)); self.none("\n");
self.none(TAB);
self.none(NEXT_LINE_INDENT);
} }
let trailing_indent = if next_line_help { let trailing_indent = if next_line_help {
TAB_WIDTH * 3 TAB.len() + NEXT_LINE_INDENT.len()
} else if let Some(true) = arg.map(|a| a.is_positional()) { } else if let Some(true) = arg.map(|a| a.is_positional()) {
longest + TAB_WIDTH * 2 longest + TAB_WIDTH * 2
} else { } else {
@ -560,7 +562,7 @@ impl<'cmd, 'writer> Help<'cmd, 'writer> {
let trailing_indent = self.get_spaces(trailing_indent); let trailing_indent = self.get_spaces(trailing_indent);
let spaces = if next_line_help { let spaces = if next_line_help {
TAB_WIDTH * 3 TAB.len() + NEXT_LINE_INDENT.len()
} else { } else {
longest + TAB_WIDTH * 3 longest + TAB_WIDTH * 3
}; };
@ -932,6 +934,8 @@ impl<'cmd, 'writer> Help<'cmd, 'writer> {
} }
} }
const NEXT_LINE_INDENT: &str = " ";
type ArgSortKey = fn(arg: &Arg) -> (usize, String); type ArgSortKey = fn(arg: &Arg) -> (usize, String);
fn positional_sort_key(arg: &Arg) -> (usize, String) { fn positional_sort_key(arg: &Arg) -> (usize, String) {