diff --git a/clap_complete/src/shells/fish.rs b/clap_complete/src/shells/fish.rs index 1c070b2fb98..a6177ae7df9 100644 --- a/clap_complete/src/shells/fish.rs +++ b/clap_complete/src/shells/fish.rs @@ -136,11 +136,14 @@ fn gen_fish_inner( buffer.push('\n'); } + let has_positionals = cmd.get_positionals().next().is_some(); + if !has_positionals { + basic_template.push_str(" -f"); + } for subcommand in cmd.get_subcommands() { 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_name).as_str()); if let Some(data) = subcommand.get_about() { diff --git a/clap_complete/tests/snapshots/feature_sample.fish b/clap_complete/tests/snapshots/feature_sample.fish index 60a0716b3c1..da54b624d0b 100644 --- a/clap_complete/tests/snapshots/feature_sample.fish +++ b/clap_complete/tests/snapshots/feature_sample.fish @@ -1,8 +1,8 @@ complete -c my-app -n "__fish_use_subcommand" -s c -s C -l config -l conf -d 'some config file' 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 "help" -d 'Print this message or the help of the given subcommand(s)' +complete -c my-app -n "__fish_use_subcommand" -a "test" -d 'tests things' +complete -c my-app -n "__fish_use_subcommand" -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' complete -c my-app -n "__fish_seen_subcommand_from test" -s V -l version -d 'Print version' diff --git a/clap_complete/tests/snapshots/special_commands.fish b/clap_complete/tests/snapshots/special_commands.fish index dd7d0b54eeb..c7eb3e7b19f 100644 --- a/clap_complete/tests/snapshots/special_commands.fish +++ b/clap_complete/tests/snapshots/special_commands.fish @@ -1,11 +1,11 @@ complete -c my-app -n "__fish_use_subcommand" -s c -s C -l config -l conf -d 'some config file' 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 'tests other things' -complete -c my-app -n "__fish_use_subcommand" -f -a "some-cmd-with-hyphens" -complete -c my-app -n "__fish_use_subcommand" -f -a "some-hidden-cmd" -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_use_subcommand" -a "test" -d 'tests things' +complete -c my-app -n "__fish_use_subcommand" -a "some_cmd" -d 'tests other things' +complete -c my-app -n "__fish_use_subcommand" -a "some-cmd-with-hyphens" +complete -c my-app -n "__fish_use_subcommand" -a "some-hidden-cmd" +complete -c my-app -n "__fish_use_subcommand" -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' complete -c my-app -n "__fish_seen_subcommand_from test" -s V -l version -d 'Print version' diff --git a/clap_complete/tests/snapshots/sub_subcommands.fish b/clap_complete/tests/snapshots/sub_subcommands.fish index 7188ca31164..3b2b0ea3a91 100644 --- a/clap_complete/tests/snapshots/sub_subcommands.fish +++ b/clap_complete/tests/snapshots/sub_subcommands.fish @@ -1,10 +1,10 @@ complete -c my-app -n "__fish_use_subcommand" -s c -s C -l config -l conf -d 'some config file' 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_use_subcommand" -a "test" -d 'tests things' +complete -c my-app -n "__fish_use_subcommand" -a "some_cmd" -d 'top level subcommand' +complete -c my-app -n "__fish_use_subcommand" -a "some_cmd_alias" -d 'top level subcommand' +complete -c my-app -n "__fish_use_subcommand" -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' complete -c my-app -n "__fish_seen_subcommand_from test" -s V -l version -d 'Print version' diff --git a/clap_complete/tests/snapshots/subcommand_last.fish b/clap_complete/tests/snapshots/subcommand_last.fish index 16d7fdb0203..c4cdd44065d 100644 --- a/clap_complete/tests/snapshots/subcommand_last.fish +++ b/clap_complete/tests/snapshots/subcommand_last.fish @@ -1,7 +1,7 @@ complete -c my-app -n "__fish_use_subcommand" -s h -l help -d 'Print help' -complete -c my-app -n "__fish_use_subcommand" -f -a "foo" -complete -c my-app -n "__fish_use_subcommand" -f -a "bar" -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_use_subcommand" -a "foo" +complete -c my-app -n "__fish_use_subcommand" -a "bar" +complete -c my-app -n "__fish_use_subcommand" -a "help" -d 'Print this message or the help of the given subcommand(s)' complete -c my-app -n "__fish_seen_subcommand_from foo" -s h -l help -d 'Print help' complete -c my-app -n "__fish_seen_subcommand_from bar" -s h -l help -d 'Print help' complete -c my-app -n "__fish_seen_subcommand_from help; and not __fish_seen_subcommand_from foo bar help" -f -a "foo"