Skip to content

Commit

Permalink
refactor(help): Break term width calculation out
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Jul 17, 2023
1 parent 33feb65 commit f8d86dc
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions clap_builder/src/output/help_template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,22 @@ impl<'cmd, 'writer> HelpTemplate<'cmd, 'writer> {
cmd.get_name(),
use_long
);
let term_w = match cmd.get_term_width() {
let term_w = Self::term_w(cmd);
let next_line_help = cmd.is_next_line_help_set();

HelpTemplate {
writer,
cmd,
styles: cmd.get_styles(),
usage,
next_line_help,
term_w,
use_long,
}
}

fn term_w(cmd: &'cmd Command) -> usize {
match cmd.get_term_width() {
Some(0) => usize::MAX,
Some(w) => w,
None => {
Expand All @@ -113,17 +128,6 @@ impl<'cmd, 'writer> HelpTemplate<'cmd, 'writer> {
};
cmp::min(current_width, max_width)
}
};
let next_line_help = cmd.is_next_line_help_set();

HelpTemplate {
writer,
cmd,
styles: cmd.get_styles(),
usage,
next_line_help,
term_w,
use_long,
}
}

Expand Down

0 comments on commit f8d86dc

Please sign in to comment.