Skip to content

Commit

Permalink
fix(builder): Fully recurse when building
Browse files Browse the repository at this point in the history
Besides addressing the panic from assuming things were built when they
weren't, this should fix some completion issues for some people.

Fixes #3669
  • Loading branch information
epage committed May 1, 2022
1 parent c6849e2 commit c972e95
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/build/command.rs
Expand Up @@ -4008,11 +4008,15 @@ impl<'help> App<'help> {
/// Call this on the top-level [`Command`] when done building and before reading state for
/// cases like completions, custom help output, etc.
pub fn build(&mut self) {
self._build_recursive();
self._build_bin_names_internal();
}

pub(crate) fn _build_recursive(&mut self) {
self._build_self();
for subcmd in self.get_subcommands_mut() {
subcmd._build_self();
subcmd._build_recursive();
}
self._build_bin_names_internal();
}

pub(crate) fn _build_self(&mut self) {
Expand Down
16 changes: 16 additions & 0 deletions tests/builder/tests.rs
Expand Up @@ -408,3 +408,19 @@ fn mut_arg_all() {
cmd = cmd.mut_arg(arg_name, |arg| arg.hide_possible_values(true));
}
}

#[test]
fn issue_3669_command_build_recurses() {
let mut cmd = Command::new("ctest").subcommand(
Command::new("subcmd").subcommand(
Command::new("multi")
.about("tests subcommands")
.author("Kevin K. <kbknapp@gmail.com>")
.version("0.1")
.arg(clap::arg!(
<FLAG> "tests flags"
)),
),
);
cmd.build();
}

0 comments on commit c972e95

Please sign in to comment.