Skip to content

Commit 7101c64

Browse files
authored
Merge pull request #5557 from tesuji/fish-positional-args-files
fish: Use --no-files on subcommands if has no positional args
2 parents 3a2fb25 + 5ee1a25 commit 7101c64

File tree

5 files changed

+18
-15
lines changed

5 files changed

+18
-15
lines changed

clap_complete/src/shells/fish.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,14 @@ fn gen_fish_inner(
136136
buffer.push('\n');
137137
}
138138

139+
let has_positionals = cmd.get_positionals().next().is_some();
140+
if !has_positionals {
141+
basic_template.push_str(" -f");
142+
}
139143
for subcommand in cmd.get_subcommands() {
140144
for subcommand_name in subcommand.get_name_and_visible_aliases() {
141145
let mut template = basic_template.clone();
142146

143-
template.push_str(" -f");
144147
template.push_str(format!(" -a \"{}\"", subcommand_name).as_str());
145148

146149
if let Some(data) = subcommand.get_about() {

clap_complete/tests/snapshots/feature_sample.fish

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
complete -c my-app -n "__fish_use_subcommand" -s c -s C -l config -l conf -d 'some config file'
22
complete -c my-app -n "__fish_use_subcommand" -s h -l help -d 'Print help'
33
complete -c my-app -n "__fish_use_subcommand" -s V -l version -d 'Print version'
4-
complete -c my-app -n "__fish_use_subcommand" -f -a "test" -d 'tests things'
5-
complete -c my-app -n "__fish_use_subcommand" -f -a "help" -d 'Print this message or the help of the given subcommand(s)'
4+
complete -c my-app -n "__fish_use_subcommand" -a "test" -d 'tests things'
5+
complete -c my-app -n "__fish_use_subcommand" -a "help" -d 'Print this message or the help of the given subcommand(s)'
66
complete -c my-app -n "__fish_seen_subcommand_from test" -l case -d 'the case to test' -r
77
complete -c my-app -n "__fish_seen_subcommand_from test" -s h -l help -d 'Print help'
88
complete -c my-app -n "__fish_seen_subcommand_from test" -s V -l version -d 'Print version'

clap_complete/tests/snapshots/special_commands.fish

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
complete -c my-app -n "__fish_use_subcommand" -s c -s C -l config -l conf -d 'some config file'
22
complete -c my-app -n "__fish_use_subcommand" -s h -l help -d 'Print help'
33
complete -c my-app -n "__fish_use_subcommand" -s V -l version -d 'Print version'
4-
complete -c my-app -n "__fish_use_subcommand" -f -a "test" -d 'tests things'
5-
complete -c my-app -n "__fish_use_subcommand" -f -a "some_cmd" -d 'tests other things'
6-
complete -c my-app -n "__fish_use_subcommand" -f -a "some-cmd-with-hyphens"
7-
complete -c my-app -n "__fish_use_subcommand" -f -a "some-hidden-cmd"
8-
complete -c my-app -n "__fish_use_subcommand" -f -a "help" -d 'Print this message or the help of the given subcommand(s)'
4+
complete -c my-app -n "__fish_use_subcommand" -a "test" -d 'tests things'
5+
complete -c my-app -n "__fish_use_subcommand" -a "some_cmd" -d 'tests other things'
6+
complete -c my-app -n "__fish_use_subcommand" -a "some-cmd-with-hyphens"
7+
complete -c my-app -n "__fish_use_subcommand" -a "some-hidden-cmd"
8+
complete -c my-app -n "__fish_use_subcommand" -a "help" -d 'Print this message or the help of the given subcommand(s)'
99
complete -c my-app -n "__fish_seen_subcommand_from test" -l case -d 'the case to test' -r
1010
complete -c my-app -n "__fish_seen_subcommand_from test" -s h -l help -d 'Print help'
1111
complete -c my-app -n "__fish_seen_subcommand_from test" -s V -l version -d 'Print version'

clap_complete/tests/snapshots/sub_subcommands.fish

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
complete -c my-app -n "__fish_use_subcommand" -s c -s C -l config -l conf -d 'some config file'
22
complete -c my-app -n "__fish_use_subcommand" -s h -l help -d 'Print help'
33
complete -c my-app -n "__fish_use_subcommand" -s V -l version -d 'Print version'
4-
complete -c my-app -n "__fish_use_subcommand" -f -a "test" -d 'tests things'
5-
complete -c my-app -n "__fish_use_subcommand" -f -a "some_cmd" -d 'top level subcommand'
6-
complete -c my-app -n "__fish_use_subcommand" -f -a "some_cmd_alias" -d 'top level subcommand'
7-
complete -c my-app -n "__fish_use_subcommand" -f -a "help" -d 'Print this message or the help of the given subcommand(s)'
4+
complete -c my-app -n "__fish_use_subcommand" -a "test" -d 'tests things'
5+
complete -c my-app -n "__fish_use_subcommand" -a "some_cmd" -d 'top level subcommand'
6+
complete -c my-app -n "__fish_use_subcommand" -a "some_cmd_alias" -d 'top level subcommand'
7+
complete -c my-app -n "__fish_use_subcommand" -a "help" -d 'Print this message or the help of the given subcommand(s)'
88
complete -c my-app -n "__fish_seen_subcommand_from test" -l case -d 'the case to test' -r
99
complete -c my-app -n "__fish_seen_subcommand_from test" -s h -l help -d 'Print help'
1010
complete -c my-app -n "__fish_seen_subcommand_from test" -s V -l version -d 'Print version'

clap_complete/tests/snapshots/subcommand_last.fish

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
complete -c my-app -n "__fish_use_subcommand" -s h -l help -d 'Print help'
2-
complete -c my-app -n "__fish_use_subcommand" -f -a "foo"
3-
complete -c my-app -n "__fish_use_subcommand" -f -a "bar"
4-
complete -c my-app -n "__fish_use_subcommand" -f -a "help" -d 'Print this message or the help of the given subcommand(s)'
2+
complete -c my-app -n "__fish_use_subcommand" -a "foo"
3+
complete -c my-app -n "__fish_use_subcommand" -a "bar"
4+
complete -c my-app -n "__fish_use_subcommand" -a "help" -d 'Print this message or the help of the given subcommand(s)'
55
complete -c my-app -n "__fish_seen_subcommand_from foo" -s h -l help -d 'Print help'
66
complete -c my-app -n "__fish_seen_subcommand_from bar" -s h -l help -d 'Print help'
77
complete -c my-app -n "__fish_seen_subcommand_from help; and not __fish_seen_subcommand_from foo bar help" -f -a "foo"

0 commit comments

Comments
 (0)