mirror of
https://github.com/clap-rs/clap
synced 2025-03-04 15:27:16 +00:00
fix(help): Show possible values long help
This commit is contained in:
parent
c6a3871544
commit
9a913c40e1
3 changed files with 22 additions and 19 deletions
|
@ -4677,6 +4677,22 @@ impl<'help> Arg<'help> {
|
|||
}
|
||||
}
|
||||
|
||||
pub(crate) fn get_possible_values2(&self) -> Vec<PossibleValue<'help>> {
|
||||
#![allow(deprecated)]
|
||||
if !self.is_takes_value_set() {
|
||||
vec![]
|
||||
} else if let Some(pvs) = self.get_possible_values() {
|
||||
// Check old first in case the user explicitly set possible values and the derive inferred
|
||||
// a `ValueParser` with some.
|
||||
pvs.to_vec()
|
||||
} else {
|
||||
self.get_value_parser()
|
||||
.possible_values()
|
||||
.map(|pvs| pvs.collect())
|
||||
.unwrap_or_default()
|
||||
}
|
||||
}
|
||||
|
||||
/// Get the names of values for this argument.
|
||||
#[inline]
|
||||
pub fn get_value_names(&self) -> Option<&[&'help str]> {
|
||||
|
|
|
@ -4902,7 +4902,9 @@ impl<'help> App<'help> {
|
|||
|| v.is_hide_long_help_set()
|
||||
|| v.is_hide_short_help_set()
|
||||
|| cfg!(feature = "unstable-v4")
|
||||
&& v.possible_vals.iter().any(PossibleValue::should_show_help)
|
||||
&& v.get_possible_values2()
|
||||
.iter()
|
||||
.any(PossibleValue::should_show_help)
|
||||
};
|
||||
|
||||
// Subcommands aren't checked because we prefer short help for them, deferring to
|
||||
|
|
|
@ -65,7 +65,7 @@ impl<'help, 'cmd, 'writer> Help<'help, 'cmd, 'writer> {
|
|||
usage: &'cmd Usage<'help, 'cmd>,
|
||||
use_long: bool,
|
||||
) -> Self {
|
||||
debug!("Help::new");
|
||||
debug!("Help::new cmd={}, use_long={}", cmd.get_name(), use_long);
|
||||
let term_w = match cmd.get_term_width() {
|
||||
Some(0) => usize::MAX,
|
||||
Some(w) => w,
|
||||
|
@ -456,7 +456,7 @@ impl<'help, 'cmd, 'writer> Help<'help, 'cmd, 'writer> {
|
|||
if let Some(arg) = arg {
|
||||
const DASH_SPACE: usize = "- ".len();
|
||||
const COLON_SPACE: usize = ": ".len();
|
||||
let possible_vals = get_possible_values(arg);
|
||||
let possible_vals = arg.get_possible_values2();
|
||||
if self.use_long
|
||||
&& !arg.is_hide_possible_values_set()
|
||||
&& possible_vals.iter().any(PossibleValue::should_show_help)
|
||||
|
@ -658,7 +658,7 @@ impl<'help, 'cmd, 'writer> Help<'help, 'cmd, 'writer> {
|
|||
}
|
||||
}
|
||||
|
||||
let possible_vals = get_possible_values(a);
|
||||
let possible_vals = a.get_possible_values2();
|
||||
if !(a.is_hide_possible_values_set()
|
||||
|| possible_vals.is_empty()
|
||||
|| cfg!(feature = "unstable-v4")
|
||||
|
@ -1141,21 +1141,6 @@ fn text_wrapper(help: &str, width: usize) -> String {
|
|||
.join("\n")
|
||||
}
|
||||
|
||||
fn get_possible_values<'help>(a: &Arg<'help>) -> Vec<PossibleValue<'help>> {
|
||||
if !a.is_takes_value_set() {
|
||||
vec![]
|
||||
} else if let Some(pvs) = a.get_possible_values() {
|
||||
// Check old first in case the user explicitly set possible values and the derive inferred
|
||||
// a `ValueParser` with some.
|
||||
pvs.to_vec()
|
||||
} else {
|
||||
a.get_value_parser()
|
||||
.possible_values()
|
||||
.map(|pvs| pvs.collect())
|
||||
.unwrap_or_default()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
|
|
Loading…
Add table
Reference in a new issue