mirror of
https://github.com/clap-rs/clap
synced 2024-12-13 14:22:34 +00:00
Merge pull request #3909 from emersonford/fix-mut-subcommand-lifetime
fix: loosen lifetime constraint on mut_subcommand
This commit is contained in:
commit
3802a35a43
2 changed files with 21 additions and 2 deletions
|
@ -298,10 +298,10 @@ impl<'help> App<'help> {
|
|||
/// assert!(res.is_ok());
|
||||
/// ```
|
||||
#[must_use]
|
||||
pub fn mut_subcommand<T, F>(mut self, subcmd_id: T, f: F) -> Self
|
||||
pub fn mut_subcommand<'a, T, F>(mut self, subcmd_id: T, f: F) -> Self
|
||||
where
|
||||
F: FnOnce(App<'help>) -> App<'help>,
|
||||
T: Into<&'help str>,
|
||||
T: Into<&'a str>,
|
||||
{
|
||||
let subcmd_id: &str = subcmd_id.into();
|
||||
let id = Id::from(subcmd_id);
|
||||
|
|
|
@ -445,6 +445,25 @@ fn mut_subcommand_all() {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn mut_subcommand_with_alias_resolve() {
|
||||
let mut cmd =
|
||||
Command::new("foo").subcommand(Command::new("bar").alias("baz").about("test subcmd"));
|
||||
assert_eq!(
|
||||
cmd.find_subcommand("baz").unwrap().get_about().unwrap(),
|
||||
"test subcmd"
|
||||
);
|
||||
|
||||
let true_name = cmd.find_subcommand("baz").unwrap().get_name().to_string();
|
||||
assert_eq!(true_name, "bar");
|
||||
|
||||
cmd = cmd.mut_subcommand(&*true_name, |subcmd| subcmd.about("modified about"));
|
||||
assert_eq!(
|
||||
cmd.find_subcommand("baz").unwrap().get_about().unwrap(),
|
||||
"modified about"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn issue_3669_command_build_recurses() {
|
||||
let mut cmd = Command::new("ctest").subcommand(
|
||||
|
|
Loading…
Reference in a new issue