Skip to content

Commit 7b5bc66

Browse files
committed
fix(complete): PS short options not case-sensitive
fixes #2145
1 parent 7353b2b commit 7b5bc66

File tree

7 files changed

+22
-20
lines changed

7 files changed

+22
-20
lines changed

clap_complete/src/shells/powershell.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,9 @@ fn generate_aliases(completions: &mut String, preamble: &String, arg: &Arg) {
124124
for alias in aliases {
125125
let _ = write!(
126126
completions,
127-
"{preamble}'-{alias}', '{alias}', [CompletionResultType]::ParameterName, '{tooltip}')"
127+
"{preamble}'-{alias}', '{alias}{}', [CompletionResultType]::ParameterName, '{tooltip}')",
128+
// make PowerShell realize there is a difference between `-s` and `-S`
129+
if alias.is_uppercase() { " " } else { "" },
128130
);
129131
}
130132
}

clap_complete/tests/snapshots/aliases.ps1

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,16 @@ Register-ArgumentCompleter -Native -CommandName 'my-app' -ScriptBlock {
2222
$completions = @(switch ($command) {
2323
'my-app' {
2424
[CompletionResult]::new('-o', 'o', [CompletionResultType]::ParameterName, 'cmd option')
25-
[CompletionResult]::new('-O', 'O', [CompletionResultType]::ParameterName, 'cmd option')
25+
[CompletionResult]::new('-O', 'O ', [CompletionResultType]::ParameterName, 'cmd option')
2626
[CompletionResult]::new('--option', 'option', [CompletionResultType]::ParameterName, 'cmd option')
2727
[CompletionResult]::new('--opt', 'opt', [CompletionResultType]::ParameterName, 'cmd option')
2828
[CompletionResult]::new('-f', 'f', [CompletionResultType]::ParameterName, 'cmd flag')
29-
[CompletionResult]::new('-F', 'F', [CompletionResultType]::ParameterName, 'cmd flag')
29+
[CompletionResult]::new('-F', 'F ', [CompletionResultType]::ParameterName, 'cmd flag')
3030
[CompletionResult]::new('--flag', 'flag', [CompletionResultType]::ParameterName, 'cmd flag')
3131
[CompletionResult]::new('--flg', 'flg', [CompletionResultType]::ParameterName, 'cmd flag')
3232
[CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Print help')
3333
[CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help')
34-
[CompletionResult]::new('-V', 'V', [CompletionResultType]::ParameterName, 'Print version')
34+
[CompletionResult]::new('-V', 'V ', [CompletionResultType]::ParameterName, 'Print version')
3535
[CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Print version')
3636
break
3737
}

clap_complete/tests/snapshots/feature_sample.ps1

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ Register-ArgumentCompleter -Native -CommandName 'my-app' -ScriptBlock {
2222
$completions = @(switch ($command) {
2323
'my-app' {
2424
[CompletionResult]::new('-c', 'c', [CompletionResultType]::ParameterName, 'some config file')
25-
[CompletionResult]::new('-C', 'C', [CompletionResultType]::ParameterName, 'some config file')
25+
[CompletionResult]::new('-C', 'C ', [CompletionResultType]::ParameterName, 'some config file')
2626
[CompletionResult]::new('--config', 'config', [CompletionResultType]::ParameterName, 'some config file')
2727
[CompletionResult]::new('--conf', 'conf', [CompletionResultType]::ParameterName, 'some config file')
2828
[CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Print help')
2929
[CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help')
30-
[CompletionResult]::new('-V', 'V', [CompletionResultType]::ParameterName, 'Print version')
30+
[CompletionResult]::new('-V', 'V ', [CompletionResultType]::ParameterName, 'Print version')
3131
[CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Print version')
3232
[CompletionResult]::new('test', 'test', [CompletionResultType]::ParameterValue, 'tests things')
3333
[CompletionResult]::new('help', 'help', [CompletionResultType]::ParameterValue, 'Print this message or the help of the given subcommand(s)')
@@ -37,7 +37,7 @@ Register-ArgumentCompleter -Native -CommandName 'my-app' -ScriptBlock {
3737
[CompletionResult]::new('--case', 'case', [CompletionResultType]::ParameterName, 'the case to test')
3838
[CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Print help')
3939
[CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help')
40-
[CompletionResult]::new('-V', 'V', [CompletionResultType]::ParameterName, 'Print version')
40+
[CompletionResult]::new('-V', 'V ', [CompletionResultType]::ParameterName, 'Print version')
4141
[CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Print version')
4242
break
4343
}

clap_complete/tests/snapshots/quoting.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Register-ArgumentCompleter -Native -CommandName 'my-app' -ScriptBlock {
2929
[CompletionResult]::new('--expansions', 'expansions', [CompletionResultType]::ParameterName, 'Execute the shell command with $SHELL')
3030
[CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Print help')
3131
[CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help')
32-
[CompletionResult]::new('-V', 'V', [CompletionResultType]::ParameterName, 'Print version')
32+
[CompletionResult]::new('-V', 'V ', [CompletionResultType]::ParameterName, 'Print version')
3333
[CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Print version')
3434
[CompletionResult]::new('cmd-single-quotes', 'cmd-single-quotes', [CompletionResultType]::ParameterValue, 'Can be ''always'', ''auto'', or ''never''')
3535
[CompletionResult]::new('cmd-double-quotes', 'cmd-double-quotes', [CompletionResultType]::ParameterValue, 'Can be "always", "auto", or "never"')

clap_complete/tests/snapshots/special_commands.ps1

+6-6
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ Register-ArgumentCompleter -Native -CommandName 'my-app' -ScriptBlock {
2222
$completions = @(switch ($command) {
2323
'my-app' {
2424
[CompletionResult]::new('-c', 'c', [CompletionResultType]::ParameterName, 'some config file')
25-
[CompletionResult]::new('-C', 'C', [CompletionResultType]::ParameterName, 'some config file')
25+
[CompletionResult]::new('-C', 'C ', [CompletionResultType]::ParameterName, 'some config file')
2626
[CompletionResult]::new('--config', 'config', [CompletionResultType]::ParameterName, 'some config file')
2727
[CompletionResult]::new('--conf', 'conf', [CompletionResultType]::ParameterName, 'some config file')
2828
[CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Print help')
2929
[CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help')
30-
[CompletionResult]::new('-V', 'V', [CompletionResultType]::ParameterName, 'Print version')
30+
[CompletionResult]::new('-V', 'V ', [CompletionResultType]::ParameterName, 'Print version')
3131
[CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Print version')
3232
[CompletionResult]::new('test', 'test', [CompletionResultType]::ParameterValue, 'tests things')
3333
[CompletionResult]::new('some_cmd', 'some_cmd', [CompletionResultType]::ParameterValue, 'tests other things')
@@ -40,29 +40,29 @@ Register-ArgumentCompleter -Native -CommandName 'my-app' -ScriptBlock {
4040
[CompletionResult]::new('--case', 'case', [CompletionResultType]::ParameterName, 'the case to test')
4141
[CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Print help')
4242
[CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help')
43-
[CompletionResult]::new('-V', 'V', [CompletionResultType]::ParameterName, 'Print version')
43+
[CompletionResult]::new('-V', 'V ', [CompletionResultType]::ParameterName, 'Print version')
4444
[CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Print version')
4545
break
4646
}
4747
'my-app;some_cmd' {
4848
[CompletionResult]::new('--config', 'config', [CompletionResultType]::ParameterName, 'the other case to test')
4949
[CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Print help')
5050
[CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help')
51-
[CompletionResult]::new('-V', 'V', [CompletionResultType]::ParameterName, 'Print version')
51+
[CompletionResult]::new('-V', 'V ', [CompletionResultType]::ParameterName, 'Print version')
5252
[CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Print version')
5353
break
5454
}
5555
'my-app;some-cmd-with-hyphens' {
5656
[CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Print help')
5757
[CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help')
58-
[CompletionResult]::new('-V', 'V', [CompletionResultType]::ParameterName, 'Print version')
58+
[CompletionResult]::new('-V', 'V ', [CompletionResultType]::ParameterName, 'Print version')
5959
[CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Print version')
6060
break
6161
}
6262
'my-app;some-hidden-cmd' {
6363
[CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Print help')
6464
[CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help')
65-
[CompletionResult]::new('-V', 'V', [CompletionResultType]::ParameterName, 'Print version')
65+
[CompletionResult]::new('-V', 'V ', [CompletionResultType]::ParameterName, 'Print version')
6666
[CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Print version')
6767
break
6868
}

clap_complete/tests/snapshots/sub_subcommands.ps1

+5-5
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ Register-ArgumentCompleter -Native -CommandName 'my-app' -ScriptBlock {
2222
$completions = @(switch ($command) {
2323
'my-app' {
2424
[CompletionResult]::new('-c', 'c', [CompletionResultType]::ParameterName, 'some config file')
25-
[CompletionResult]::new('-C', 'C', [CompletionResultType]::ParameterName, 'some config file')
25+
[CompletionResult]::new('-C', 'C ', [CompletionResultType]::ParameterName, 'some config file')
2626
[CompletionResult]::new('--config', 'config', [CompletionResultType]::ParameterName, 'some config file')
2727
[CompletionResult]::new('--conf', 'conf', [CompletionResultType]::ParameterName, 'some config file')
2828
[CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Print help')
2929
[CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help')
30-
[CompletionResult]::new('-V', 'V', [CompletionResultType]::ParameterName, 'Print version')
30+
[CompletionResult]::new('-V', 'V ', [CompletionResultType]::ParameterName, 'Print version')
3131
[CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Print version')
3232
[CompletionResult]::new('test', 'test', [CompletionResultType]::ParameterValue, 'tests things')
3333
[CompletionResult]::new('some_cmd', 'some_cmd', [CompletionResultType]::ParameterValue, 'top level subcommand')
@@ -38,14 +38,14 @@ Register-ArgumentCompleter -Native -CommandName 'my-app' -ScriptBlock {
3838
[CompletionResult]::new('--case', 'case', [CompletionResultType]::ParameterName, 'the case to test')
3939
[CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Print help')
4040
[CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help')
41-
[CompletionResult]::new('-V', 'V', [CompletionResultType]::ParameterName, 'Print version')
41+
[CompletionResult]::new('-V', 'V ', [CompletionResultType]::ParameterName, 'Print version')
4242
[CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Print version')
4343
break
4444
}
4545
'my-app;some_cmd' {
4646
[CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Print help')
4747
[CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help')
48-
[CompletionResult]::new('-V', 'V', [CompletionResultType]::ParameterName, 'Print version')
48+
[CompletionResult]::new('-V', 'V ', [CompletionResultType]::ParameterName, 'Print version')
4949
[CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Print version')
5050
[CompletionResult]::new('sub_cmd', 'sub_cmd', [CompletionResultType]::ParameterValue, 'sub-subcommand')
5151
[CompletionResult]::new('help', 'help', [CompletionResultType]::ParameterValue, 'Print this message or the help of the given subcommand(s)')
@@ -55,7 +55,7 @@ Register-ArgumentCompleter -Native -CommandName 'my-app' -ScriptBlock {
5555
[CompletionResult]::new('--config', 'config', [CompletionResultType]::ParameterName, 'the other case to test')
5656
[CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Print help (see more with ''--help'')')
5757
[CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help (see more with ''--help'')')
58-
[CompletionResult]::new('-V', 'V', [CompletionResultType]::ParameterName, 'Print version')
58+
[CompletionResult]::new('-V', 'V ', [CompletionResultType]::ParameterName, 'Print version')
5959
[CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Print version')
6060
break
6161
}

clap_complete/tests/snapshots/value_hint.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Register-ArgumentCompleter -Native -CommandName 'my-app' -ScriptBlock {
3737
[CompletionResult]::new('--cmd', 'cmd', [CompletionResultType]::ParameterName, 'cmd')
3838
[CompletionResult]::new('-u', 'u', [CompletionResultType]::ParameterName, 'u')
3939
[CompletionResult]::new('--user', 'user', [CompletionResultType]::ParameterName, 'user')
40-
[CompletionResult]::new('-H', 'H', [CompletionResultType]::ParameterName, 'H')
40+
[CompletionResult]::new('-H', 'H ', [CompletionResultType]::ParameterName, 'H')
4141
[CompletionResult]::new('--host', 'host', [CompletionResultType]::ParameterName, 'host')
4242
[CompletionResult]::new('--url', 'url', [CompletionResultType]::ParameterName, 'url')
4343
[CompletionResult]::new('--email', 'email', [CompletionResultType]::ParameterName, 'email')

0 commit comments

Comments
 (0)