Skip to content

Commit

Permalink
fix(fish): Don't ignore files if has positional args
Browse files Browse the repository at this point in the history
  • Loading branch information
tesuji committed Jun 28, 2024
1 parent 3a2fb25 commit 5ee1a25
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 15 deletions.
5 changes: 4 additions & 1 deletion clap_complete/src/shells/fish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
4 changes: 2 additions & 2 deletions clap_complete/tests/snapshots/feature_sample.fish
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
10 changes: 5 additions & 5 deletions clap_complete/tests/snapshots/special_commands.fish
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
8 changes: 4 additions & 4 deletions clap_complete/tests/snapshots/sub_subcommands.fish
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
6 changes: 3 additions & 3 deletions clap_complete/tests/snapshots/subcommand_last.fish
Original file line number Diff line number Diff line change
@@ -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"
Expand Down

0 comments on commit 5ee1a25

Please sign in to comment.