-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow user to add completion for powershell alias #1621
Conversation
How does this work with the other shells at the moment? I do not use powershell any more but I think this will work. Back when I worked on this there weren't many projects with powershell completion so I am not sure if there is maybe some pseudo standard which can/should be followed. |
This whole idea came out of a comment from the PR that added Powershell completion to kubectl: kubernetes/kubernetes#103758 (comment) There was a project that implemented a hard-coded script for powershell completion for kubectl which handled aliases in this way. This is the specific line that inspired me: https://github.com/mziyabo/PSKubectlCompletion/blob/f6f28153a616e14789a3a7fbcb493ff7f1f1ae85/PSKubectlCompletion.psm1#L20 |
I personally do not like to pollute the global variable scope in the shell but the variable name seems reasonable unique so it should be fine. Since there is a legitimate use case for this and I cannot offer a better solution I am fine with this PR. |
Hmmmmm anyone out in the community have an easy way to test this on Windows? I'm without my windows box at the moment. |
The Cobra project currently lacks enough contributors to adequately respond to all PRs. This bot triages issues and PRs according to the following rules:
|
Still valid |
983311a
to
5453964
Compare
I fixed this PR which is still relevant. |
When a user has an alias in powershell, she will need to register that alias for completion. To make that possible, we store the completion logic into a scriptblock variable which can easily be accessed by the user to register aliases. For example, if the user defines an alias for `helm`: PS> sal h helm she will need to register the alias like so: PS> Register-ArgumentCompleter -CommandName 'h' -ScriptBlock $__helmCompleterBlock Signed-off-by: Marc Khouzam <marc.khouzam@montreal.ca>
5453964
to
6ba7ebb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@marckhouzam @Luap99 - I see this has the lgtm
label: I am still without a windows box suitable for testing :( is this good to go? Code looks good to me and If you feel ok with this Marc, go ahead and self merge
Yeah, it is ready. I am able to test it on powershell on Mac, and @Luap99 is happy with the change. Will merge. |
Sorry. But why doesn't it work for me?
|
What version of kubectl are you using? I believe you need 1.26 or higher. |
Yeah. Sorry to bother you. Kubectl 1.26+ depends on cobra 1.6.0 with this pr. thank you it works . |
When a user has an alias in powershell, she will need to register that alias for completion. To make that possible, we store the completion logic into a scriptblock variable which can easily be accessed by the user to register aliases. For example, if the user defines an alias for `helm`: PS> sal h helm she will need to register the alias like so: PS> Register-ArgumentCompleter -CommandName 'h' -ScriptBlock $__helmCompleterBlock Merge spf13/cobra#1621
I ran across a possible problem with using powershell completion with aliases. I can't recall where it was though, but the situation is pretty simple.
IIUC, when a user has an alias in powershell, she needs to register that alias for completion using:
The problem is that the
<completionBlock>
is currently not accessible in our powershell script.To address this, this commit stores the completion logic into a scriptblock variable which can easily be accessed by the
user to register aliases.
For example, if the user defines an alias for
helm
she will be able to register an alias like this:@Luap99 does this make sense to you? I may be misunderstanding something fundamental about aliases and powershell...