Skip to content

Commit

Permalink
fix(complete): PS short options not case-sensitive
Browse files Browse the repository at this point in the history
fixes #2145
  • Loading branch information
RubixDev committed Jul 4, 2023
1 parent 7353b2b commit 7b5bc66
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 20 deletions.
4 changes: 3 additions & 1 deletion clap_complete/src/shells/powershell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ fn generate_aliases(completions: &mut String, preamble: &String, arg: &Arg) {
for alias in aliases {
let _ = write!(
completions,
"{preamble}'-{alias}', '{alias}', [CompletionResultType]::ParameterName, '{tooltip}')"
"{preamble}'-{alias}', '{alias}{}', [CompletionResultType]::ParameterName, '{tooltip}')",
// make PowerShell realize there is a difference between `-s` and `-S`
if alias.is_uppercase() { " " } else { "" },
);
}
}
Expand Down
6 changes: 3 additions & 3 deletions clap_complete/tests/snapshots/aliases.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ Register-ArgumentCompleter -Native -CommandName 'my-app' -ScriptBlock {
$completions = @(switch ($command) {
'my-app' {
[CompletionResult]::new('-o', 'o', [CompletionResultType]::ParameterName, 'cmd option')
[CompletionResult]::new('-O', 'O', [CompletionResultType]::ParameterName, 'cmd option')
[CompletionResult]::new('-O', 'O ', [CompletionResultType]::ParameterName, 'cmd option')
[CompletionResult]::new('--option', 'option', [CompletionResultType]::ParameterName, 'cmd option')
[CompletionResult]::new('--opt', 'opt', [CompletionResultType]::ParameterName, 'cmd option')
[CompletionResult]::new('-f', 'f', [CompletionResultType]::ParameterName, 'cmd flag')
[CompletionResult]::new('-F', 'F', [CompletionResultType]::ParameterName, 'cmd flag')
[CompletionResult]::new('-F', 'F ', [CompletionResultType]::ParameterName, 'cmd flag')
[CompletionResult]::new('--flag', 'flag', [CompletionResultType]::ParameterName, 'cmd flag')
[CompletionResult]::new('--flg', 'flg', [CompletionResultType]::ParameterName, 'cmd flag')
[CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Print help')
[CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help')
[CompletionResult]::new('-V', 'V', [CompletionResultType]::ParameterName, 'Print version')
[CompletionResult]::new('-V', 'V ', [CompletionResultType]::ParameterName, 'Print version')
[CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Print version')
break
}
Expand Down
6 changes: 3 additions & 3 deletions clap_complete/tests/snapshots/feature_sample.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ Register-ArgumentCompleter -Native -CommandName 'my-app' -ScriptBlock {
$completions = @(switch ($command) {
'my-app' {
[CompletionResult]::new('-c', 'c', [CompletionResultType]::ParameterName, 'some config file')
[CompletionResult]::new('-C', 'C', [CompletionResultType]::ParameterName, 'some config file')
[CompletionResult]::new('-C', 'C ', [CompletionResultType]::ParameterName, 'some config file')
[CompletionResult]::new('--config', 'config', [CompletionResultType]::ParameterName, 'some config file')
[CompletionResult]::new('--conf', 'conf', [CompletionResultType]::ParameterName, 'some config file')
[CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Print help')
[CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help')
[CompletionResult]::new('-V', 'V', [CompletionResultType]::ParameterName, 'Print version')
[CompletionResult]::new('-V', 'V ', [CompletionResultType]::ParameterName, 'Print version')
[CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Print version')
[CompletionResult]::new('test', 'test', [CompletionResultType]::ParameterValue, 'tests things')
[CompletionResult]::new('help', 'help', [CompletionResultType]::ParameterValue, 'Print this message or the help of the given subcommand(s)')
Expand All @@ -37,7 +37,7 @@ Register-ArgumentCompleter -Native -CommandName 'my-app' -ScriptBlock {
[CompletionResult]::new('--case', 'case', [CompletionResultType]::ParameterName, 'the case to test')
[CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Print help')
[CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help')
[CompletionResult]::new('-V', 'V', [CompletionResultType]::ParameterName, 'Print version')
[CompletionResult]::new('-V', 'V ', [CompletionResultType]::ParameterName, 'Print version')
[CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Print version')
break
}
Expand Down
2 changes: 1 addition & 1 deletion clap_complete/tests/snapshots/quoting.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Register-ArgumentCompleter -Native -CommandName 'my-app' -ScriptBlock {
[CompletionResult]::new('--expansions', 'expansions', [CompletionResultType]::ParameterName, 'Execute the shell command with $SHELL')
[CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Print help')
[CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help')
[CompletionResult]::new('-V', 'V', [CompletionResultType]::ParameterName, 'Print version')
[CompletionResult]::new('-V', 'V ', [CompletionResultType]::ParameterName, 'Print version')
[CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Print version')
[CompletionResult]::new('cmd-single-quotes', 'cmd-single-quotes', [CompletionResultType]::ParameterValue, 'Can be ''always'', ''auto'', or ''never''')
[CompletionResult]::new('cmd-double-quotes', 'cmd-double-quotes', [CompletionResultType]::ParameterValue, 'Can be "always", "auto", or "never"')
Expand Down
12 changes: 6 additions & 6 deletions clap_complete/tests/snapshots/special_commands.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ Register-ArgumentCompleter -Native -CommandName 'my-app' -ScriptBlock {
$completions = @(switch ($command) {
'my-app' {
[CompletionResult]::new('-c', 'c', [CompletionResultType]::ParameterName, 'some config file')
[CompletionResult]::new('-C', 'C', [CompletionResultType]::ParameterName, 'some config file')
[CompletionResult]::new('-C', 'C ', [CompletionResultType]::ParameterName, 'some config file')
[CompletionResult]::new('--config', 'config', [CompletionResultType]::ParameterName, 'some config file')
[CompletionResult]::new('--conf', 'conf', [CompletionResultType]::ParameterName, 'some config file')
[CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Print help')
[CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help')
[CompletionResult]::new('-V', 'V', [CompletionResultType]::ParameterName, 'Print version')
[CompletionResult]::new('-V', 'V ', [CompletionResultType]::ParameterName, 'Print version')
[CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Print version')
[CompletionResult]::new('test', 'test', [CompletionResultType]::ParameterValue, 'tests things')
[CompletionResult]::new('some_cmd', 'some_cmd', [CompletionResultType]::ParameterValue, 'tests other things')
Expand All @@ -40,29 +40,29 @@ Register-ArgumentCompleter -Native -CommandName 'my-app' -ScriptBlock {
[CompletionResult]::new('--case', 'case', [CompletionResultType]::ParameterName, 'the case to test')
[CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Print help')
[CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help')
[CompletionResult]::new('-V', 'V', [CompletionResultType]::ParameterName, 'Print version')
[CompletionResult]::new('-V', 'V ', [CompletionResultType]::ParameterName, 'Print version')
[CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Print version')
break
}
'my-app;some_cmd' {
[CompletionResult]::new('--config', 'config', [CompletionResultType]::ParameterName, 'the other case to test')
[CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Print help')
[CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help')
[CompletionResult]::new('-V', 'V', [CompletionResultType]::ParameterName, 'Print version')
[CompletionResult]::new('-V', 'V ', [CompletionResultType]::ParameterName, 'Print version')
[CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Print version')
break
}
'my-app;some-cmd-with-hyphens' {
[CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Print help')
[CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help')
[CompletionResult]::new('-V', 'V', [CompletionResultType]::ParameterName, 'Print version')
[CompletionResult]::new('-V', 'V ', [CompletionResultType]::ParameterName, 'Print version')
[CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Print version')
break
}
'my-app;some-hidden-cmd' {
[CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Print help')
[CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help')
[CompletionResult]::new('-V', 'V', [CompletionResultType]::ParameterName, 'Print version')
[CompletionResult]::new('-V', 'V ', [CompletionResultType]::ParameterName, 'Print version')
[CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Print version')
break
}
Expand Down
10 changes: 5 additions & 5 deletions clap_complete/tests/snapshots/sub_subcommands.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ Register-ArgumentCompleter -Native -CommandName 'my-app' -ScriptBlock {
$completions = @(switch ($command) {
'my-app' {
[CompletionResult]::new('-c', 'c', [CompletionResultType]::ParameterName, 'some config file')
[CompletionResult]::new('-C', 'C', [CompletionResultType]::ParameterName, 'some config file')
[CompletionResult]::new('-C', 'C ', [CompletionResultType]::ParameterName, 'some config file')
[CompletionResult]::new('--config', 'config', [CompletionResultType]::ParameterName, 'some config file')
[CompletionResult]::new('--conf', 'conf', [CompletionResultType]::ParameterName, 'some config file')
[CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Print help')
[CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help')
[CompletionResult]::new('-V', 'V', [CompletionResultType]::ParameterName, 'Print version')
[CompletionResult]::new('-V', 'V ', [CompletionResultType]::ParameterName, 'Print version')
[CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Print version')
[CompletionResult]::new('test', 'test', [CompletionResultType]::ParameterValue, 'tests things')
[CompletionResult]::new('some_cmd', 'some_cmd', [CompletionResultType]::ParameterValue, 'top level subcommand')
Expand All @@ -38,14 +38,14 @@ Register-ArgumentCompleter -Native -CommandName 'my-app' -ScriptBlock {
[CompletionResult]::new('--case', 'case', [CompletionResultType]::ParameterName, 'the case to test')
[CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Print help')
[CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help')
[CompletionResult]::new('-V', 'V', [CompletionResultType]::ParameterName, 'Print version')
[CompletionResult]::new('-V', 'V ', [CompletionResultType]::ParameterName, 'Print version')
[CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Print version')
break
}
'my-app;some_cmd' {
[CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Print help')
[CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help')
[CompletionResult]::new('-V', 'V', [CompletionResultType]::ParameterName, 'Print version')
[CompletionResult]::new('-V', 'V ', [CompletionResultType]::ParameterName, 'Print version')
[CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Print version')
[CompletionResult]::new('sub_cmd', 'sub_cmd', [CompletionResultType]::ParameterValue, 'sub-subcommand')
[CompletionResult]::new('help', 'help', [CompletionResultType]::ParameterValue, 'Print this message or the help of the given subcommand(s)')
Expand All @@ -55,7 +55,7 @@ Register-ArgumentCompleter -Native -CommandName 'my-app' -ScriptBlock {
[CompletionResult]::new('--config', 'config', [CompletionResultType]::ParameterName, 'the other case to test')
[CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Print help (see more with ''--help'')')
[CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help (see more with ''--help'')')
[CompletionResult]::new('-V', 'V', [CompletionResultType]::ParameterName, 'Print version')
[CompletionResult]::new('-V', 'V ', [CompletionResultType]::ParameterName, 'Print version')
[CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Print version')
break
}
Expand Down
2 changes: 1 addition & 1 deletion clap_complete/tests/snapshots/value_hint.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Register-ArgumentCompleter -Native -CommandName 'my-app' -ScriptBlock {
[CompletionResult]::new('--cmd', 'cmd', [CompletionResultType]::ParameterName, 'cmd')
[CompletionResult]::new('-u', 'u', [CompletionResultType]::ParameterName, 'u')
[CompletionResult]::new('--user', 'user', [CompletionResultType]::ParameterName, 'user')
[CompletionResult]::new('-H', 'H', [CompletionResultType]::ParameterName, 'H')
[CompletionResult]::new('-H', 'H ', [CompletionResultType]::ParameterName, 'H')
[CompletionResult]::new('--host', 'host', [CompletionResultType]::ParameterName, 'host')
[CompletionResult]::new('--url', 'url', [CompletionResultType]::ParameterName, 'url')
[CompletionResult]::new('--email', 'email', [CompletionResultType]::ParameterName, 'email')
Expand Down

0 comments on commit 7b5bc66

Please sign in to comment.