mirror of
https://github.com/clap-rs/clap
synced 2025-01-06 09:48:43 +00:00
Merge #2976
2976: fix: Loosen reflection lifetimes r=pksunkara a=epage Co-authored-by: Ed Page <eopage@gmail.com>
This commit is contained in:
commit
c8acf5debd
3 changed files with 28 additions and 14 deletions
|
@ -115,7 +115,7 @@ impl<'help> App<'help> {
|
||||||
|
|
||||||
/// Get the long flag of the subcommand.
|
/// Get the long flag of the subcommand.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn get_long_flag(&self) -> Option<&str> {
|
pub fn get_long_flag(&self) -> Option<&'help str> {
|
||||||
self.long_flag
|
self.long_flag
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,7 +134,7 @@ impl<'help> App<'help> {
|
||||||
///
|
///
|
||||||
/// [`App::about`]: App::about()
|
/// [`App::about`]: App::about()
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn get_about(&self) -> Option<&str> {
|
pub fn get_about(&self) -> Option<&'help str> {
|
||||||
self.about
|
self.about
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,7 +142,7 @@ impl<'help> App<'help> {
|
||||||
///
|
///
|
||||||
/// [`App::long_about`]: App::long_about()
|
/// [`App::long_about`]: App::long_about()
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn get_long_about(&self) -> Option<&str> {
|
pub fn get_long_about(&self) -> Option<&'help str> {
|
||||||
self.long_about
|
self.long_about
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -156,7 +156,7 @@ impl<'help> App<'help> {
|
||||||
|
|
||||||
/// Iterate through the *visible* aliases for this subcommand.
|
/// Iterate through the *visible* aliases for this subcommand.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn get_visible_aliases(&self) -> impl Iterator<Item = &str> {
|
pub fn get_visible_aliases(&self) -> impl Iterator<Item = &'help str> + '_ {
|
||||||
self.aliases.iter().filter(|(_, vis)| *vis).map(|a| a.0)
|
self.aliases.iter().filter(|(_, vis)| *vis).map(|a| a.0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -180,7 +180,7 @@ impl<'help> App<'help> {
|
||||||
|
|
||||||
/// Iterate through the set of *all* the aliases for this subcommand, both visible and hidden.
|
/// Iterate through the set of *all* the aliases for this subcommand, both visible and hidden.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn get_all_aliases(&self) -> impl Iterator<Item = &str> {
|
pub fn get_all_aliases(&self) -> impl Iterator<Item = &str> + '_ {
|
||||||
self.aliases.iter().map(|a| a.0)
|
self.aliases.iter().map(|a| a.0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -128,13 +128,13 @@ pub struct Arg<'help> {
|
||||||
impl<'help> Arg<'help> {
|
impl<'help> Arg<'help> {
|
||||||
/// Get the name of the argument
|
/// Get the name of the argument
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn get_name(&self) -> &str {
|
pub fn get_name(&self) -> &'help str {
|
||||||
self.name
|
self.name
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the help specified for this argument, if any
|
/// Get the help specified for this argument, if any
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn get_about(&self) -> Option<&str> {
|
pub fn get_about(&self) -> Option<&'help str> {
|
||||||
self.about
|
self.about
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -149,13 +149,13 @@ impl<'help> Arg<'help> {
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn get_long_about(&self) -> Option<&str> {
|
pub fn get_long_about(&self) -> Option<&'help str> {
|
||||||
self.long_about
|
self.long_about
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the help heading specified for this argument, if any
|
/// Get the help heading specified for this argument, if any
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn get_help_heading(&self) -> Option<&str> {
|
pub fn get_help_heading(&self) -> Option<&'help str> {
|
||||||
self.help_heading.unwrap_or_default()
|
self.help_heading.unwrap_or_default()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -196,13 +196,13 @@ impl<'help> Arg<'help> {
|
||||||
|
|
||||||
/// Get the long option name for this argument, if any
|
/// Get the long option name for this argument, if any
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn get_long(&self) -> Option<&str> {
|
pub fn get_long(&self) -> Option<&'help str> {
|
||||||
self.long
|
self.long
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get visible aliases for this argument, if any
|
/// Get visible aliases for this argument, if any
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn get_visible_aliases(&self) -> Option<Vec<&str>> {
|
pub fn get_visible_aliases(&self) -> Option<Vec<&'help str>> {
|
||||||
if self.aliases.is_empty() {
|
if self.aliases.is_empty() {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
|
@ -218,7 +218,7 @@ impl<'help> Arg<'help> {
|
||||||
|
|
||||||
/// Get the long option name and its visible aliases, if any
|
/// Get the long option name and its visible aliases, if any
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn get_long_and_visible_aliases(&self) -> Option<Vec<&str>> {
|
pub fn get_long_and_visible_aliases(&self) -> Option<Vec<&'help str>> {
|
||||||
let mut longs = match self.long {
|
let mut longs = match self.long {
|
||||||
Some(long) => vec![long],
|
Some(long) => vec![long],
|
||||||
None => return None,
|
None => return None,
|
||||||
|
@ -241,7 +241,7 @@ impl<'help> Arg<'help> {
|
||||||
|
|
||||||
/// Get the names of values for this argument.
|
/// Get the names of values for this argument.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn get_value_names(&self) -> Option<&[&str]> {
|
pub fn get_value_names(&self) -> Option<&[&'help str]> {
|
||||||
if self.val_names.is_empty() {
|
if self.val_names.is_empty() {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -3,7 +3,7 @@ mod utils;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::str;
|
use std::str;
|
||||||
|
|
||||||
use clap::{App, Arg};
|
use clap::{App, Arg, ArgSettings};
|
||||||
|
|
||||||
static SCF2OP: &str = "flag present 2 times
|
static SCF2OP: &str = "flag present 2 times
|
||||||
option NOT present
|
option NOT present
|
||||||
|
@ -390,3 +390,17 @@ fn sc_short_flag_x2_short_opt_eq_pos() {
|
||||||
fn sc_short_flag_x2_long_opt_eq_pos() {
|
fn sc_short_flag_x2_long_opt_eq_pos() {
|
||||||
check_complex_output("clap-test subcmd value -f -f --option=some", SCF2OP);
|
check_complex_output("clap-test subcmd value -f -f --option=some", SCF2OP);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn mut_arg_all() {
|
||||||
|
let mut app = utils::complex_app();
|
||||||
|
let arg_names = app
|
||||||
|
.get_arguments()
|
||||||
|
.map(|a| a.get_name())
|
||||||
|
.filter(|a| *a != "version" && *a != "help")
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
|
for arg_name in arg_names {
|
||||||
|
app = app.mut_arg(arg_name, |arg| arg.setting(ArgSettings::HidePossibleValues));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue