Skip to content

Commit

Permalink
fix(help): 🐛 folded help was duplicating auto-generated commands (#324)
Browse files Browse the repository at this point in the history
This happened when having commands following the same general path but
with steps auto-generated. The help was not merging those in the
expected way.
  • Loading branch information
XaF authored Jan 2, 2024
1 parent 5cb0e1e commit 78c425a
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/internal/commands/builtin/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ impl HelpCommandOrganizer {

fn add_command(&mut self, path: Vec<String>, command: &Command) {
let mut command_itself = true;
let mut inserted_paths = vec![path.clone()].into_iter().collect::<HashSet<_>>();

for i in (1..=path.len()).rev() {
let (cmdpath, _) = path.split_at(i);
Expand All @@ -417,14 +418,14 @@ impl HelpCommandOrganizer {
// Check if that key already exists in the commands
if let Some(cmd) = self.commands.get_mut(&key) {
if !command_itself {
cmd.subcommands.insert(path.clone());
cmd.subcommands.extend(inserted_paths.clone());
continue;
}

match cmd.command {
Command::Void(_) => {
cmd.command = command.clone();
cmd.subcommands.insert(path.clone());
cmd.subcommands.extend(inserted_paths.clone());
}
_ => {
// Command exists twice in the path, but second entry in the path
Expand All @@ -444,8 +445,12 @@ impl HelpCommandOrganizer {
};

let mut new_command = HelpCommandMetadata::new(&insert_command);
new_command.subcommands.insert(path.clone());
new_command.subcommands.extend(inserted_paths.clone());
self.commands.insert(key, new_command);

if !command_itself {
inserted_paths.insert(cmdpath.to_vec());
}
}

command_itself = false;
Expand Down

0 comments on commit 78c425a

Please sign in to comment.