Skip to content

Commit 23e16e5

Browse files
committed
fix(clap_complete_nushell): order positional arguments by index
1 parent 89569da commit 23e16e5

File tree

7 files changed

+22
-13
lines changed

7 files changed

+22
-13
lines changed

clap_complete_nushell/src/lib.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,16 @@ fn generate_completion(completions: &mut String, cmd: &Command, is_subcommand: b
219219
completions.push_str(format!(" export extern {name} [\n").as_str());
220220
}
221221

222-
for arg in cmd.get_arguments() {
222+
let flags: Vec<_> = cmd.get_arguments().filter(|a| !a.is_positional()).collect();
223+
let mut positionals: Vec<_> = cmd.get_positionals().collect();
224+
225+
positionals.sort_by_key(|arg| arg.get_index());
226+
227+
for arg in flags {
228+
append_argument(arg, name, completions);
229+
}
230+
231+
for arg in positionals {
223232
append_argument(arg, name, completions);
224233
}
225234

clap_complete_nushell/tests/snapshots/aliases.nu

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ module completions {
88
--option(-o): string # cmd option
99
--opt: string # cmd option
1010
-O: string # cmd option
11-
positional?: string
1211
--help(-h) # Print help
1312
--version(-V) # Print version
13+
positional?: string
1414
]
1515

1616
}

clap_complete_nushell/tests/snapshots/feature_sample.nu

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ module completions {
66

77
# Tests completions
88
export extern my-app [
9-
file?: path # some input file
109
--config(-c) # some config file with another line
1110
--conf # some config file with another line
1211
-C # some config file with another line
13-
choice?: string@"nu-complete my-app choice"
1412
--help(-h) # Print help
1513
--version(-V) # Print version
14+
file?: path # some input file
15+
choice?: string@"nu-complete my-app choice"
1616
]
1717

1818
# tests things

clap_complete_nushell/tests/snapshots/positional_index.nu

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ module completions {
33
# Tests positional argument index ordering
44
export extern my-app [
55
--flag(-f) # some flag
6-
third?: string # third positional
7-
first?: string # first positional
86
--option(-o): string # some option
9-
second?: string # second positional
107
--help(-h) # Print help
118
--version(-V) # Print version
9+
first?: string # first positional
10+
second?: string # second positional
11+
third?: string # third positional
1212
]
1313

1414
}

clap_complete_nushell/tests/snapshots/special_commands.nu

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ module completions {
66

77
# Tests completions
88
export extern my-app [
9-
file?: path # some input file
109
--config(-c) # some config file with another line
1110
--conf # some config file with another line
1211
-C # some config file with another line
13-
choice?: string@"nu-complete my-app choice"
1412
--help(-h) # Print help
1513
--version(-V) # Print version
14+
file?: path # some input file
15+
choice?: string@"nu-complete my-app choice"
1616
]
1717

1818
# tests things
@@ -25,9 +25,9 @@ module completions {
2525
# tests other things
2626
export extern "my-app some_cmd" [
2727
--config: string # the other case to test
28-
...path: string
2928
--help(-h) # Print help
3029
--version(-V) # Print version
30+
...path: string
3131
]
3232

3333
export extern "my-app some-cmd-with-hyphens" [

clap_complete_nushell/tests/snapshots/sub_subcommands.nu

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ module completions {
66

77
# Tests completions
88
export extern my-app [
9-
file?: path # some input file
109
--config(-c) # some config file with another line
1110
--conf # some config file with another line
1211
-C # some config file with another line
13-
choice?: string@"nu-complete my-app choice"
1412
--help(-h) # Print help
1513
--version(-V) # Print version
14+
file?: path # some input file
15+
choice?: string@"nu-complete my-app choice"
1616
]
1717

1818
# tests things

clap_complete_nushell/tests/snapshots/value_hint.nu

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ module completions {
1414
--exe(-e): path
1515
--cmd-name: string
1616
--cmd(-c): string
17-
command_with_args?: string
1817
--user(-u): string
1918
--host(-H): string
2019
--url: string
2120
--email: string
2221
--help(-h) # Print help
22+
command_with_args?: string
2323
]
2424

2525
}

0 commit comments

Comments
 (0)