Skip to content

Commit

Permalink
fix: loosen lifetime constraint on mut_subcommand
Browse files Browse the repository at this point in the history
  • Loading branch information
emersonford committed Jul 12, 2022
1 parent 5c7ad01 commit 7bc0075
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/builder/command.rs
Expand Up @@ -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);
Expand Down
19 changes: 19 additions & 0 deletions tests/builder/tests.rs
Expand Up @@ -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(
Expand Down

0 comments on commit 7bc0075

Please sign in to comment.