fix(help): Defaulting max_term_width instead of max_term_width

Fixes #4295
This commit is contained in:
Ed Page 2023-07-17 09:40:49 -05:00
parent d741e9519c
commit bc000aa4b0
4 changed files with 53 additions and 0 deletions

View file

@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Breaking Changes
- Made `ArgPredicate` `non_exhaustive`
- *(help)* Change default `Command::term_width` to "source format"
- *(help)* Change default `Command::max_term_width` to 100
- *(derive)* `Vec<Vec<T>>` types are now assuming to capture occurrences
### Features

View file

@ -1132,6 +1132,9 @@ impl Command {
/// Defaults to current terminal width when `wrap_help` feature flag is enabled. If current
/// width cannot be determined, the default is 100.
///
/// **`unstable-v5` feature**: Defaults to unbound, being subject to
/// [`Command::max_term_width`].
///
/// **NOTE:** This setting applies globally and *not* on a per-command basis.
///
/// **NOTE:** This requires the `wrap_help` feature
@ -1160,6 +1163,8 @@ impl Command {
///
/// Using `0` will ignore this, always respecting [`Command::term_width`] (default).
///
/// **`unstable-v5` feature**: Defaults to 100.
///
/// **NOTE:** This setting applies globally and *not* on a per-command basis.
///
/// **NOTE:** This requires the `wrap_help` feature

View file

@ -115,6 +115,7 @@ impl<'cmd, 'writer> HelpTemplate<'cmd, 'writer> {
}
}
#[cfg(not(feature = "unstable-v5"))]
fn term_w(cmd: &'cmd Command) -> usize {
match cmd.get_term_width() {
Some(0) => usize::MAX,
@ -131,6 +132,26 @@ impl<'cmd, 'writer> HelpTemplate<'cmd, 'writer> {
}
}
#[cfg(feature = "unstable-v5")]
fn term_w(cmd: &'cmd Command) -> usize {
let term_w = match cmd.get_term_width() {
Some(0) => usize::MAX,
Some(w) => w,
None => {
let (current_width, _h) = dimensions();
current_width.unwrap_or(usize::MAX)
}
};
let max_term_w = match cmd.get_max_term_width() {
Some(0) => usize::MAX,
Some(mw) => mw,
None => 100,
};
cmp::min(term_w, max_term_w)
}
/// Write help to stream for the parser in the format defined by the template.
///
/// For details about the template language see [`Command::help_template`].

View file

@ -916,6 +916,7 @@ fn old_newline_variables() {
#[test]
#[cfg(feature = "wrap_help")]
fn issue_688_hide_pos_vals() {
#[cfg(not(feature = "unstable-v5"))]
static ISSUE_688: &str = "\
Usage: ctest [OPTIONS]
@ -927,6 +928,18 @@ Options:
-V, --version Print version
";
#[cfg(feature = "unstable-v5")]
static ISSUE_688: &str = "\
Usage: ctest [OPTIONS]
Options:
--filter <filter> Sets the filter, or sampling method, to use for interpolation when resizing
the particle images. The default is Linear (Bilinear). [possible values:
Nearest, Linear, Cubic, Gaussian, Lanczos3]
-h, --help Print help
-V, --version Print version
";
let filter_values = ["Nearest", "Linear", "Cubic", "Gaussian", "Lanczos3"];
let app1 = Command::new("ctest")
@ -1511,6 +1524,7 @@ fn hide_default_val() {
#[test]
#[cfg(feature = "wrap_help")]
fn escaped_whitespace_values() {
#[cfg(not(feature = "unstable-v5"))]
static ESCAPED_DEFAULT_VAL: &str = "\
Usage: default [OPTIONS]
@ -1521,6 +1535,17 @@ Options:
-V, --version Print version
";
#[cfg(feature = "unstable-v5")]
static ESCAPED_DEFAULT_VAL: &str = "\
Usage: default [OPTIONS]
Options:
--arg <argument> Pass an argument to the program. [default: \"\\n\"] [possible values: normal, \"
\", \"\\n\", \"\\t\", other]
-h, --help Print help
-V, --version Print version
";
let app1 = Command::new("default").version("0.1").term_width(120).arg(
Arg::new("argument")
.help("Pass an argument to the program.")