Skip to content

Commit 1e3681b

Browse files
committed
refactor: Pass list to __fish_seen_subcommand_from
1 parent b1a0508 commit 1e3681b

File tree

9 files changed

+132
-128
lines changed

9 files changed

+132
-128
lines changed

clap_complete/src/shells/fish.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,20 @@ fn gen_fish_inner(
6767
basic_template.push_str(" -n \"__fish_use_subcommand\"");
6868
}
6969
} else {
70-
let mut out = String::new();
70+
let mut out = String::from("__fish_seen_subcommand_from");
7171
for &command in parent_commands {
72-
out.push_str("__fish_seen_subcommand_from ");
72+
out.push(' ');
7373
out.push_str(command);
7474
}
75-
for name in cmd
75+
let subcommands: Vec<&str> = cmd
7676
.get_subcommands()
7777
.flat_map(Command::get_name_and_visible_aliases)
78-
{
79-
out.push_str("; and not __fish_seen_subcommand_from ");
78+
.collect();
79+
if !subcommands.is_empty() {
80+
out.push_str("; and not __fish_seen_subcommand_from");
81+
}
82+
for name in subcommands {
83+
out.push(' ');
8084
out.push_str(name);
8185
}
8286
basic_template.push_str(format!(" -n \"{out}\"").as_str());

clap_complete/tests/snapshots/basic.fish

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ complete -c my-app -n "__fish_use_subcommand" -f -a "help" -d 'Print this messag
66
complete -c my-app -n "__fish_seen_subcommand_from test" -s d
77
complete -c my-app -n "__fish_seen_subcommand_from test" -s c
88
complete -c my-app -n "__fish_seen_subcommand_from test" -s h -l help -d 'Print help'
9-
complete -c my-app -n "__fish_seen_subcommand_from help; and not __fish_seen_subcommand_from test; and not __fish_seen_subcommand_from help" -f -a "test" -d 'Subcommand with a second line'
10-
complete -c my-app -n "__fish_seen_subcommand_from help; and not __fish_seen_subcommand_from test; and not __fish_seen_subcommand_from help" -f -a "help" -d 'Print this message or the help of the given subcommand(s)'
9+
complete -c my-app -n "__fish_seen_subcommand_from help; and not __fish_seen_subcommand_from test help" -f -a "test" -d 'Subcommand with a second line'
10+
complete -c my-app -n "__fish_seen_subcommand_from help; and not __fish_seen_subcommand_from test help" -f -a "help" -d 'Print this message or the help of the given subcommand(s)'

clap_complete/tests/snapshots/custom_bin_name.fish

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ complete -c bin-name -n "__fish_use_subcommand" -f -a "help" -d 'Print this mess
66
complete -c bin-name -n "__fish_seen_subcommand_from test" -s d
77
complete -c bin-name -n "__fish_seen_subcommand_from test" -s c
88
complete -c bin-name -n "__fish_seen_subcommand_from test" -s h -l help -d 'Print help'
9-
complete -c bin-name -n "__fish_seen_subcommand_from help; and not __fish_seen_subcommand_from test; and not __fish_seen_subcommand_from help" -f -a "test" -d 'Subcommand with a second line'
10-
complete -c bin-name -n "__fish_seen_subcommand_from help; and not __fish_seen_subcommand_from test; and not __fish_seen_subcommand_from help" -f -a "help" -d 'Print this message or the help of the given subcommand(s)'
9+
complete -c bin-name -n "__fish_seen_subcommand_from help; and not __fish_seen_subcommand_from test help" -f -a "test" -d 'Subcommand with a second line'
10+
complete -c bin-name -n "__fish_seen_subcommand_from help; and not __fish_seen_subcommand_from test help" -f -a "help" -d 'Print this message or the help of the given subcommand(s)'

clap_complete/tests/snapshots/feature_sample.fish

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ complete -c my-app -n "__fish_use_subcommand" -f -a "help" -d 'Print this messag
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'
9-
complete -c my-app -n "__fish_seen_subcommand_from help; and not __fish_seen_subcommand_from test; and not __fish_seen_subcommand_from help" -f -a "test" -d 'tests things'
10-
complete -c my-app -n "__fish_seen_subcommand_from help; and not __fish_seen_subcommand_from test; and not __fish_seen_subcommand_from help" -f -a "help" -d 'Print this message or the help of the given subcommand(s)'
9+
complete -c my-app -n "__fish_seen_subcommand_from help; and not __fish_seen_subcommand_from test help" -f -a "test" -d 'tests things'
10+
complete -c my-app -n "__fish_seen_subcommand_from help; and not __fish_seen_subcommand_from test help" -f -a "help" -d 'Print this message or the help of the given subcommand(s)'

clap_complete/tests/snapshots/home/static/exhaustive/fish/fish/completions/exhaustive.fish

+80-80
Large diffs are not rendered by default.

clap_complete/tests/snapshots/quoting.fish

+7-7
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ complete -c my-app -n "__fish_seen_subcommand_from cmd-backticks" -s h -l help -
1919
complete -c my-app -n "__fish_seen_subcommand_from cmd-backslash" -s h -l help -d 'Print help'
2020
complete -c my-app -n "__fish_seen_subcommand_from cmd-brackets" -s h -l help -d 'Print help'
2121
complete -c my-app -n "__fish_seen_subcommand_from cmd-expansions" -s h -l help -d 'Print help'
22-
complete -c my-app -n "__fish_seen_subcommand_from help; and not __fish_seen_subcommand_from cmd-single-quotes; and not __fish_seen_subcommand_from cmd-double-quotes; and not __fish_seen_subcommand_from cmd-backticks; and not __fish_seen_subcommand_from cmd-backslash; and not __fish_seen_subcommand_from cmd-brackets; and not __fish_seen_subcommand_from cmd-expansions; and not __fish_seen_subcommand_from help" -f -a "cmd-single-quotes" -d 'Can be \'always\', \'auto\', or \'never\''
23-
complete -c my-app -n "__fish_seen_subcommand_from help; and not __fish_seen_subcommand_from cmd-single-quotes; and not __fish_seen_subcommand_from cmd-double-quotes; and not __fish_seen_subcommand_from cmd-backticks; and not __fish_seen_subcommand_from cmd-backslash; and not __fish_seen_subcommand_from cmd-brackets; and not __fish_seen_subcommand_from cmd-expansions; and not __fish_seen_subcommand_from help" -f -a "cmd-double-quotes" -d 'Can be "always", "auto", or "never"'
24-
complete -c my-app -n "__fish_seen_subcommand_from help; and not __fish_seen_subcommand_from cmd-single-quotes; and not __fish_seen_subcommand_from cmd-double-quotes; and not __fish_seen_subcommand_from cmd-backticks; and not __fish_seen_subcommand_from cmd-backslash; and not __fish_seen_subcommand_from cmd-brackets; and not __fish_seen_subcommand_from cmd-expansions; and not __fish_seen_subcommand_from help" -f -a "cmd-backticks" -d 'For more information see `echo test`'
25-
complete -c my-app -n "__fish_seen_subcommand_from help; and not __fish_seen_subcommand_from cmd-single-quotes; and not __fish_seen_subcommand_from cmd-double-quotes; and not __fish_seen_subcommand_from cmd-backticks; and not __fish_seen_subcommand_from cmd-backslash; and not __fish_seen_subcommand_from cmd-brackets; and not __fish_seen_subcommand_from cmd-expansions; and not __fish_seen_subcommand_from help" -f -a "cmd-backslash" -d 'Avoid \'\\n\''
26-
complete -c my-app -n "__fish_seen_subcommand_from help; and not __fish_seen_subcommand_from cmd-single-quotes; and not __fish_seen_subcommand_from cmd-double-quotes; and not __fish_seen_subcommand_from cmd-backticks; and not __fish_seen_subcommand_from cmd-backslash; and not __fish_seen_subcommand_from cmd-brackets; and not __fish_seen_subcommand_from cmd-expansions; and not __fish_seen_subcommand_from help" -f -a "cmd-brackets" -d 'List packages [filter]'
27-
complete -c my-app -n "__fish_seen_subcommand_from help; and not __fish_seen_subcommand_from cmd-single-quotes; and not __fish_seen_subcommand_from cmd-double-quotes; and not __fish_seen_subcommand_from cmd-backticks; and not __fish_seen_subcommand_from cmd-backslash; and not __fish_seen_subcommand_from cmd-brackets; and not __fish_seen_subcommand_from cmd-expansions; and not __fish_seen_subcommand_from help" -f -a "cmd-expansions" -d 'Execute the shell command with $SHELL'
28-
complete -c my-app -n "__fish_seen_subcommand_from help; and not __fish_seen_subcommand_from cmd-single-quotes; and not __fish_seen_subcommand_from cmd-double-quotes; and not __fish_seen_subcommand_from cmd-backticks; and not __fish_seen_subcommand_from cmd-backslash; and not __fish_seen_subcommand_from cmd-brackets; and not __fish_seen_subcommand_from cmd-expansions; and not __fish_seen_subcommand_from help" -f -a "help" -d 'Print this message or the help of the given subcommand(s)'
22+
complete -c my-app -n "__fish_seen_subcommand_from help; and not __fish_seen_subcommand_from cmd-single-quotes cmd-double-quotes cmd-backticks cmd-backslash cmd-brackets cmd-expansions help" -f -a "cmd-single-quotes" -d 'Can be \'always\', \'auto\', or \'never\''
23+
complete -c my-app -n "__fish_seen_subcommand_from help; and not __fish_seen_subcommand_from cmd-single-quotes cmd-double-quotes cmd-backticks cmd-backslash cmd-brackets cmd-expansions help" -f -a "cmd-double-quotes" -d 'Can be "always", "auto", or "never"'
24+
complete -c my-app -n "__fish_seen_subcommand_from help; and not __fish_seen_subcommand_from cmd-single-quotes cmd-double-quotes cmd-backticks cmd-backslash cmd-brackets cmd-expansions help" -f -a "cmd-backticks" -d 'For more information see `echo test`'
25+
complete -c my-app -n "__fish_seen_subcommand_from help; and not __fish_seen_subcommand_from cmd-single-quotes cmd-double-quotes cmd-backticks cmd-backslash cmd-brackets cmd-expansions help" -f -a "cmd-backslash" -d 'Avoid \'\\n\''
26+
complete -c my-app -n "__fish_seen_subcommand_from help; and not __fish_seen_subcommand_from cmd-single-quotes cmd-double-quotes cmd-backticks cmd-backslash cmd-brackets cmd-expansions help" -f -a "cmd-brackets" -d 'List packages [filter]'
27+
complete -c my-app -n "__fish_seen_subcommand_from help; and not __fish_seen_subcommand_from cmd-single-quotes cmd-double-quotes cmd-backticks cmd-backslash cmd-brackets cmd-expansions help" -f -a "cmd-expansions" -d 'Execute the shell command with $SHELL'
28+
complete -c my-app -n "__fish_seen_subcommand_from help; and not __fish_seen_subcommand_from cmd-single-quotes cmd-double-quotes cmd-backticks cmd-backslash cmd-brackets cmd-expansions help" -f -a "help" -d 'Print this message or the help of the given subcommand(s)'

clap_complete/tests/snapshots/special_commands.fish

+5-5
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ complete -c my-app -n "__fish_seen_subcommand_from some-cmd-with-hyphens" -s h -
1616
complete -c my-app -n "__fish_seen_subcommand_from some-cmd-with-hyphens" -s V -l version -d 'Print version'
1717
complete -c my-app -n "__fish_seen_subcommand_from some-hidden-cmd" -s h -l help -d 'Print help'
1818
complete -c my-app -n "__fish_seen_subcommand_from some-hidden-cmd" -s V -l version -d 'Print version'
19-
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 some-cmd-with-hyphens; and not __fish_seen_subcommand_from some-hidden-cmd; and not __fish_seen_subcommand_from help" -f -a "test" -d 'tests things'
20-
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 some-cmd-with-hyphens; and not __fish_seen_subcommand_from some-hidden-cmd; and not __fish_seen_subcommand_from help" -f -a "some_cmd" -d 'tests other things'
21-
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 some-cmd-with-hyphens; and not __fish_seen_subcommand_from some-hidden-cmd; and not __fish_seen_subcommand_from help" -f -a "some-cmd-with-hyphens"
22-
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 some-cmd-with-hyphens; and not __fish_seen_subcommand_from some-hidden-cmd; and not __fish_seen_subcommand_from help" -f -a "some-hidden-cmd"
23-
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 some-cmd-with-hyphens; and not __fish_seen_subcommand_from some-hidden-cmd; and not __fish_seen_subcommand_from help" -f -a "help" -d 'Print this message or the help of the given subcommand(s)'
19+
complete -c my-app -n "__fish_seen_subcommand_from help; and not __fish_seen_subcommand_from test some_cmd some-cmd-with-hyphens some-hidden-cmd help" -f -a "test" -d 'tests things'
20+
complete -c my-app -n "__fish_seen_subcommand_from help; and not __fish_seen_subcommand_from test some_cmd some-cmd-with-hyphens some-hidden-cmd help" -f -a "some_cmd" -d 'tests other things'
21+
complete -c my-app -n "__fish_seen_subcommand_from help; and not __fish_seen_subcommand_from test some_cmd some-cmd-with-hyphens some-hidden-cmd help" -f -a "some-cmd-with-hyphens"
22+
complete -c my-app -n "__fish_seen_subcommand_from help; and not __fish_seen_subcommand_from test some_cmd some-cmd-with-hyphens some-hidden-cmd help" -f -a "some-hidden-cmd"
23+
complete -c my-app -n "__fish_seen_subcommand_from help; and not __fish_seen_subcommand_from test some_cmd some-cmd-with-hyphens some-hidden-cmd help" -f -a "help" -d 'Print this message or the help of the given subcommand(s)'

0 commit comments

Comments
 (0)