Skip to content

Commit

Permalink
refactor: Rewrite iterator for followup changes
Browse files Browse the repository at this point in the history
  • Loading branch information
tesuji committed Jun 27, 2024
1 parent 5cc44bb commit b1a0508
Showing 1 changed file with 13 additions and 16 deletions.
29 changes: 13 additions & 16 deletions clap_complete/src/shells/fish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +67,19 @@ fn gen_fish_inner(
basic_template.push_str(" -n \"__fish_use_subcommand\"");
}
} else {
basic_template.push_str(
format!(
" -n \"{}\"",
parent_commands
.iter()
.map(|command| format!("__fish_seen_subcommand_from {command}"))
.chain(
cmd.get_subcommands()
.flat_map(Command::get_name_and_visible_aliases)
.map(|name| format!("not __fish_seen_subcommand_from {name}"))
)
.collect::<Vec<_>>()
.join("; and ")
)
.as_str(),
);
let mut out = String::new();
for &command in parent_commands {
out.push_str("__fish_seen_subcommand_from ");
out.push_str(command);
}
for name in cmd
.get_subcommands()
.flat_map(Command::get_name_and_visible_aliases)
{
out.push_str("; and not __fish_seen_subcommand_from ");
out.push_str(name);
}
basic_template.push_str(format!(" -n \"{out}\"").as_str());
}

debug!("gen_fish_inner: parent_commands={parent_commands:?}");
Expand Down

0 comments on commit b1a0508

Please sign in to comment.