Repository: clap-rs/clap (language: rust)

Issue:
clap_generate PowerShell script does not complete case sensitive options like -S. Only completes -s
### Make sure you completed the following tasks

- [X] Searched the [discussions](https://github.com/clap-rs/clap/discussions)
- [X] Searched the closed issues

### Code

https://github.com/clap-rs/clap/blob/3e9ee86713b5c407b50ba76f30cffaed25952063/clap_generate/src/generators/shells/powershell.rs

### Steps to reproduce the issue

N/A

### Version

name = "clap"
version = "2.33.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bdfa80d47f954d53a35a64987ca1422f495b8d6483c0fe9f7117b36c2a792129"
dependencies = [
 "bitflags",
 "strsim",
 "textwrap",
 "unicode-width",
]

### Actual Behavior Summary

https://github.com/BurntSushi/ripgrep generated _rg.ps1 does not complete -S correctly. It only completes -s.

### Expected Behavior Summary

See https://github.com/BurntSushi/ripgrep/issues/1690 for details.

`.  _rg.ps1`

`rg -s<Ctrl-Space>` completes `rg -s`. It should produce:

```
rg -s
s   S

Search case sensitively (default).
```
A simple fix would be to change ListItemText for 'S' to 'S '. The space makes ListItemText unique, which is all that's needed.

### Additional context

A simple fix may be to test for upper case and append a space. I don't know rust, so a PR is beyond me.

https://github.com/clap-rs/clap/blob/3e9ee86713b5c407b50ba76f30cffaed25952063/clap_generate/src/generators/shells/powershell.rs#L94 and https://github.com/clap-rs/clap/blob/3e9ee86713b5c407b50ba76f30cffaed25952063/clap_generate/src/generators/shells/powershell.rs#L105

For example, change the second '{}' to '{} ' in the format! below after adding a check for upper case. Sorry I can't be more helpful.

```
if let Some(short_aliases) = option.get_visible_short_aliases() {
                for data in short_aliases {
                    completions.push_str(&preamble);
                    completions.push_str(
                        format!(
                            "'-{}', '{} ', {}, '{}')",
                            data, data, "[CompletionResultType]::ParameterName", tooltip
                        )
                        .as_str(),
                    );
                }
            }
        }
```

### Debug output

N/A


Discussion / hints:

Fix patch:
diff --git a/clap_complete/src/shells/powershell.rs b/clap_complete/src/shells/powershell.rs
index 417facf70c2..6b09b2e3ad8 100644
--- a/clap_complete/src/shells/powershell.rs
+++ b/clap_complete/src/shells/powershell.rs
@@ -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 { "" },
             );
         }
     }


Test patch:
diff --git a/clap_complete/tests/snapshots/aliases.ps1 b/clap_complete/tests/snapshots/aliases.ps1
index 7bc67b6a40f..5095c966091 100644
--- a/clap_complete/tests/snapshots/aliases.ps1
+++ b/clap_complete/tests/snapshots/aliases.ps1
@@ -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
         }
diff --git a/clap_complete/tests/snapshots/feature_sample.ps1 b/clap_complete/tests/snapshots/feature_sample.ps1
index 6f6dc5b9ec4..4d6853ee5c0 100644
--- a/clap_complete/tests/snapshots/feature_sample.ps1
+++ b/clap_complete/tests/snapshots/feature_sample.ps1
@@ -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)')
@@ -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
         }
diff --git a/clap_complete/tests/snapshots/quoting.ps1 b/clap_complete/tests/snapshots/quoting.ps1
index 57b6691a426..cccbc79c552 100644
--- a/clap_complete/tests/snapshots/quoting.ps1
+++ b/clap_complete/tests/snapshots/quoting.ps1
@@ -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"')
diff --git a/clap_complete/tests/snapshots/special_commands.ps1 b/clap_complete/tests/snapshots/special_commands.ps1
index f9e6a9da029..6a16ed3a67a 100644
--- a/clap_complete/tests/snapshots/special_commands.ps1
+++ b/clap_complete/tests/snapshots/special_commands.ps1
@@ -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')
@@ -40,7 +40,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
         }
@@ -48,21 +48,21 @@ 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')
             [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
         }
diff --git a/clap_complete/tests/snapshots/sub_subcommands.ps1 b/clap_complete/tests/snapshots/sub_subcommands.ps1
index 7256794316e..3880c2442ae 100644
--- a/clap_complete/tests/snapshots/sub_subcommands.ps1
+++ b/clap_complete/tests/snapshots/sub_subcommands.ps1
@@ -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')
@@ -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)')
@@ -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
         }
diff --git a/clap_complete/tests/snapshots/value_hint.ps1 b/clap_complete/tests/snapshots/value_hint.ps1
index fc2bd878c7f..b228caf3c16 100644
--- a/clap_complete/tests/snapshots/value_hint.ps1
+++ b/clap_complete/tests/snapshots/value_hint.ps1
@@ -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')