diff --git a/clap_complete/src/shells/fish.rs b/clap_complete/src/shells/fish.rs index d8e7fde1280..39d0b7f6f68 100644 --- a/clap_complete/src/shells/fish.rs +++ b/clap_complete/src/shells/fish.rs @@ -75,7 +75,8 @@ fn gen_fish_inner( .map(|command| format!("__fish_seen_subcommand_from {command}")) .chain( cmd.get_subcommands() - .map(|command| format!("not __fish_seen_subcommand_from {command}")) + .flat_map(Command::get_name_and_visible_aliases) + .map(|name| format!("not __fish_seen_subcommand_from {name}")) ) .collect::>() .join("; and ") @@ -135,24 +136,28 @@ fn gen_fish_inner( } for subcommand in cmd.get_subcommands() { - let mut template = basic_template.clone(); + for subcommand_name in subcommand.get_name_and_visible_aliases() { + let mut template = basic_template.clone(); - template.push_str(" -f"); - template.push_str(format!(" -a \"{}\"", &subcommand.get_name()).as_str()); + template.push_str(" -f"); + template.push_str(format!(" -a \"{}\"", subcommand_name).as_str()); - if let Some(data) = subcommand.get_about() { - template.push_str(format!(" -d '{}'", escape_help(data)).as_str()) - } + if let Some(data) = subcommand.get_about() { + template.push_str(format!(" -d '{}'", escape_help(data)).as_str()) + } - buffer.push_str(template.as_str()); - buffer.push('\n'); + buffer.push_str(template.as_str()); + buffer.push('\n'); + } } // generate options of subcommands for subcommand in cmd.get_subcommands() { - let mut parent_commands: Vec<_> = parent_commands.into(); - parent_commands.push(subcommand.get_name()); - gen_fish_inner(root_command, &parent_commands, subcommand, buffer); + for subcommand_name in subcommand.get_name_and_visible_aliases() { + let mut parent_commands: Vec<_> = parent_commands.into(); + parent_commands.push(subcommand_name); + gen_fish_inner(root_command, &parent_commands, subcommand, buffer); + } } } diff --git a/clap_complete/tests/snapshots/sub_subcommands.fish b/clap_complete/tests/snapshots/sub_subcommands.fish index cec51a63a1f..644e37ad494 100644 --- a/clap_complete/tests/snapshots/sub_subcommands.fish +++ b/clap_complete/tests/snapshots/sub_subcommands.fish @@ -3,6 +3,7 @@ complete -c my-app -n "__fish_use_subcommand" -s h -l help -d 'Print help' complete -c my-app -n "__fish_use_subcommand" -s V -l version -d 'Print version' complete -c my-app -n "__fish_use_subcommand" -f -a "test" -d 'tests things' complete -c my-app -n "__fish_use_subcommand" -f -a "some_cmd" -d 'top level subcommand' +complete -c my-app -n "__fish_use_subcommand" -f -a "some_cmd_alias" -d 'top level subcommand' complete -c my-app -n "__fish_use_subcommand" -f -a "help" -d 'Print this message or the help of the given subcommand(s)' complete -c my-app -n "__fish_seen_subcommand_from test" -l case -d 'the case to test' -r complete -c my-app -n "__fish_seen_subcommand_from test" -s h -l help -d 'Print help' @@ -16,6 +17,15 @@ complete -c my-app -n "__fish_seen_subcommand_from some_cmd; and __fish_seen_sub complete -c my-app -n "__fish_seen_subcommand_from some_cmd; and __fish_seen_subcommand_from sub_cmd" -s V -l version -d 'Print version' complete -c my-app -n "__fish_seen_subcommand_from some_cmd; and __fish_seen_subcommand_from help; and not __fish_seen_subcommand_from sub_cmd; and not __fish_seen_subcommand_from help" -f -a "sub_cmd" -d 'sub-subcommand' complete -c my-app -n "__fish_seen_subcommand_from some_cmd; and __fish_seen_subcommand_from help; and not __fish_seen_subcommand_from sub_cmd; and not __fish_seen_subcommand_from help" -f -a "help" -d 'Print this message or the help of the given subcommand(s)' +complete -c my-app -n "__fish_seen_subcommand_from some_cmd_alias; and not __fish_seen_subcommand_from sub_cmd; and not __fish_seen_subcommand_from help" -s h -l help -d 'Print help' +complete -c my-app -n "__fish_seen_subcommand_from some_cmd_alias; and not __fish_seen_subcommand_from sub_cmd; and not __fish_seen_subcommand_from help" -s V -l version -d 'Print version' +complete -c my-app -n "__fish_seen_subcommand_from some_cmd_alias; and not __fish_seen_subcommand_from sub_cmd; and not __fish_seen_subcommand_from help" -f -a "sub_cmd" -d 'sub-subcommand' +complete -c my-app -n "__fish_seen_subcommand_from some_cmd_alias; and not __fish_seen_subcommand_from sub_cmd; and not __fish_seen_subcommand_from help" -f -a "help" -d 'Print this message or the help of the given subcommand(s)' +complete -c my-app -n "__fish_seen_subcommand_from some_cmd_alias; and __fish_seen_subcommand_from sub_cmd" -l config -d 'the other case to test' -r -f -a "{Lest quotes\, aren\'t escaped. 'help,with,comma',Second to trigger display of options ''}" +complete -c my-app -n "__fish_seen_subcommand_from some_cmd_alias; and __fish_seen_subcommand_from sub_cmd" -s h -l help -d 'Print help (see more with \'--help\')' +complete -c my-app -n "__fish_seen_subcommand_from some_cmd_alias; and __fish_seen_subcommand_from sub_cmd" -s V -l version -d 'Print version' +complete -c my-app -n "__fish_seen_subcommand_from some_cmd_alias; and __fish_seen_subcommand_from help; and not __fish_seen_subcommand_from sub_cmd; and not __fish_seen_subcommand_from help" -f -a "sub_cmd" -d 'sub-subcommand' +complete -c my-app -n "__fish_seen_subcommand_from some_cmd_alias; and __fish_seen_subcommand_from help; and not __fish_seen_subcommand_from sub_cmd; and not __fish_seen_subcommand_from help" -f -a "help" -d 'Print this message or the help of the given subcommand(s)' complete -c my-app -n "__fish_seen_subcommand_from help; and not __fish_seen_subcommand_from test; and not __fish_seen_subcommand_from some_cmd; and not __fish_seen_subcommand_from help" -f -a "test" -d 'tests things' complete -c my-app -n "__fish_seen_subcommand_from help; and not __fish_seen_subcommand_from test; and not __fish_seen_subcommand_from some_cmd; and not __fish_seen_subcommand_from help" -f -a "some_cmd" -d 'top level subcommand' complete -c my-app -n "__fish_seen_subcommand_from help; and not __fish_seen_subcommand_from test; and not __fish_seen_subcommand_from some_cmd; and not __fish_seen_subcommand_from help" -f -a "help" -d 'Print this message or the help of the given subcommand(s)'