Skip to content

Commit 232ee10

Browse files
committed
fix(complete): Use existing display order for Arg/Command
1 parent c6b5d62 commit 232ee10

File tree

4 files changed

+21
-22
lines changed

4 files changed

+21
-22
lines changed

clap_complete/src/engine/complete.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -414,12 +414,10 @@ fn complete_subcommand(value: &str, cmd: &clap::Command) -> Vec<CompletionCandid
414414
value
415415
);
416416

417-
let mut scs = subcommands(cmd)
417+
subcommands(cmd)
418418
.into_iter()
419419
.filter(|x| x.get_value().starts_with(value))
420-
.collect::<Vec<_>>();
421-
scs.sort();
422-
scs
420+
.collect()
423421
}
424422

425423
/// Gets all the long options, their visible aliases and flags of a [`clap::Command`] with formatted `--` prefix.
@@ -487,6 +485,7 @@ fn populate_arg_candidate(candidate: CompletionCandidate, arg: &clap::Arg) -> Co
487485
.to_owned()
488486
.into(),
489487
))
488+
.display_order(Some(arg.get_display_order()))
490489
.hide(arg.is_hide_set())
491490
}
492491

@@ -535,6 +534,7 @@ fn populate_command_candidate(
535534
.to_owned()
536535
.into(),
537536
))
537+
.display_order(Some(subcommand.get_display_order()))
538538
.hide(subcommand.is_hide_set())
539539
}
540540
/// Parse the short flags and find the first `takes_values` option.

clap_complete/tests/testsuite/bash.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,8 @@ fn complete_dynamic_env_toplevel() {
255255
let input = "exhaustive \t\t";
256256
let expected = snapbox::str![[r#"
257257
%
258-
action help last quote --global --help
259-
alias hint pacman value --generate --version
258+
action value last hint --global --help
259+
quote pacman alias help --generate --version
260260
"#]];
261261
let actual = runtime.complete(input, &term).unwrap();
262262
assert_data_eq!(actual, expected);
@@ -275,9 +275,9 @@ fn complete_dynamic_env_quoted_help() {
275275
let input = "exhaustive quote \t\t";
276276
let expected = snapbox::str![[r#"
277277
%
278-
cmd-backslash cmd-double-quotes escape-help --double-quotes --brackets --global
279-
cmd-backticks cmd-expansions help --backticks --expansions --help
280-
cmd-brackets cmd-single-quotes --single-quotes --backslash --choice --version
278+
cmd-single-quotes cmd-backslash escape-help --global --backslash --choice
279+
cmd-double-quotes cmd-brackets help --double-quotes --brackets --help
280+
cmd-backticks cmd-expansions --single-quotes --backticks --expansions --version
281281
"#]];
282282
let actual = runtime.complete(input, &term).unwrap();
283283
assert_data_eq!(actual, expected);

clap_complete/tests/testsuite/engine.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ fn suggest_subcommand_subset() {
3030
assert_data_eq!(
3131
complete!(cmd, "he"),
3232
snapbox::str![[r#"
33-
hello-moon
3433
hello-world
34+
hello-moon
3535
help Print this message or the help of the given subcommand(s)
3636
"#]],
3737
);
@@ -105,8 +105,8 @@ fn suggest_subcommand_aliases() {
105105
assert_data_eq!(
106106
complete!(cmd, "hello"),
107107
snapbox::str![[r#"
108-
hello-moon
109108
hello-world
109+
hello-moon
110110
"#]],
111111
);
112112
}
@@ -1099,26 +1099,26 @@ fn sort_and_filter() {
10991099
assert_data_eq!(
11001100
complete!(cmd, " [TAB]"),
11011101
snapbox::str![[r#"
1102-
help Print this message or the help of the given subcommand(s)
11031102
sub
1103+
help Print this message or the help of the given subcommand(s)
11041104
pos-a
11051105
pos-b
11061106
pos-c
11071107
--required-flag
11081108
--optional-flag
11091109
--long-flag
1110-
--help Print help
11111110
-s
1111+
--help Print help
11121112
"#]]
11131113
);
11141114
assert_data_eq!(
11151115
complete!(cmd, "-[TAB]"),
11161116
snapbox::str![[r#"
11171117
-r --required-flag
11181118
-o --optional-flag
1119+
--long-flag
11191120
-s
11201121
-h Print help
1121-
--long-flag
11221122
"#]]
11231123
);
11241124
assert_data_eq!(

clap_complete/tests/testsuite/fish.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,9 @@ fn complete_dynamic_env_toplevel() {
192192
let input = "exhaustive \t\t";
193193
let expected = snapbox::str![[r#"
194194
% exhaustive action
195-
action last --global (everywhere)
196-
alias pacman --generate (generate)
197-
help (Print this message or the help of the given subcommand(s)) quote --help (Print help)
198-
hint value --version (Print version)
195+
action pacman hint --generate (generate)
196+
quote last help (Print this message or the help of the given subcommand(s)) --help (Print help)
197+
value alias --global (everywhere) --version (Print version)
199198
"#]];
200199
let actual = runtime.complete(input, &term).unwrap();
201200
assert_data_eq!(actual, expected);
@@ -214,22 +213,22 @@ fn complete_dynamic_env_quoted_help() {
214213
let input = "exhaustive quote \t\t";
215214
let expected = snapbox::str![[r#"
216215
% exhaustive quote
217-
cmd-backslash (Avoid '/n')
216+
cmd-single-quotes (Can be 'always', 'auto', or 'never')
217+
cmd-double-quotes (Can be "always", "auto", or "never")
218218
cmd-backticks (For more information see `echo test`)
219+
cmd-backslash (Avoid '/n')
219220
cmd-brackets (List packages [filter])
220-
cmd-double-quotes (Can be "always", "auto", or "never")
221221
cmd-expansions (Execute the shell command with $SHELL)
222-
cmd-single-quotes (Can be 'always', 'auto', or 'never')
223222
escape-help (/tab "')
224223
help (Print this message or the help of the given subcommand(s))
225224
--single-quotes (Can be 'always', 'auto', or 'never')
225+
--global (everywhere)
226226
--double-quotes (Can be "always", "auto", or "never")
227227
--backticks (For more information see `echo test`)
228228
--backslash (Avoid '/n')
229229
--brackets (List packages [filter])
230230
--expansions (Execute the shell command with $SHELL)
231231
--choice
232-
--global (everywhere)
233232
--help (Print help (see more with '--help'))
234233
--version (Print version)
235234
"#]];

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy