-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
feat(completion): support no space format of short flags #1727
Conversation
Supet exciting @fiftin ! I didn't expect it to be that simple 😁. I'll give it a try ASAP 🚀 You will have to sign the CLA before we can accept the contribution however. |
How to do this? UPDATE: Done. |
@fiftin I'm having trouble understanding what this change is supposed to provide. |
-f123[TAB] Output Before: Empty After: -f flag description |
@fiftin Sorry but I'm still having trouble understanding the behaviour you seek. If a program has a short flag |
I orientated to issue #1629. Your example in the issue:
For my opinion it should works similar to |
@fiftin
in both cases, the completion logic would suggest all namespaces that start with I believe the same behaviour should happen when there is no space after the short flag.
But there are special cases we would need to treat differently:
Does this make sense to you? |
Hi @marckhouzam, Done. Please see test Line 476 in 59f7a0c
|
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.
This is a great start @fiftin, thanks!
Testing with a real program, the go logic to handle short flags without a space seems to work as expected.
I like your idea of checking if a completion function exists to decide if
we should complete a short flag value, or if we should add a space after
the short flag.
So, when testing with the __complete command things seem good nicely.
However when testing with the actual shell while performing completions
things don't work just yet. For zsh for example, we need to set the variable flagPrefix
in the script. What I mean is that if we do
$ helm -n<tab>
and get the completion choices 'firstns' and 'secondns', the zsh completion
script must convert them into '-nfirstns' and '-nsecondns'. We already
do this for the = case:
$ helm -n=<tab>
firstns secondns
So the zsh shell script would need to be modified a little to handle the new case
of completion of short flags. The completion for bash v2 will also need
to be fixed (I haven't looked at the details, but it also does not work). And we'll need to
try things out for fish and powershell to see what they need. I can help
out with all this if you want, you just let me know.
But we are making good progress 👍
completions_test.go
Outdated
@@ -2280,7 +2350,7 @@ func removeCompCmd(rootCmd *Command) { | |||
} | |||
} | |||
|
|||
func TestDefaultCompletionCmd(t *testing.T) { | |||
func xTestDefaultCompletionCmd(t *testing.T) { |
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.
Could you re-enable this test, it passes.
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.
Hi @marckhouzam I did. I updated PR yesterday with --force flag
Hi @marckhouzam
Yes, it is possible, but we should print following completion:
In this case we get partially completed expression:
Otherwise, If we print:
We get:
I didn't find how to solve it. I suggest to complete this expression to:
Why it works with |
Hi @marckhouzam , any updates? What do you think about our issue? |
Thanks @fiftin for the effort. I will need to take the time to give this proper attention but I will not have time for the next couple of weeks. I'll get back to this as soon as I can. Thanks for your patience |
Hi @marckhouzam , Do you have a time to work on the issue? |
@fiftin Are you no longer interested in making this contribution? I was about to review it when I saw you had closed it. |
Cobra supports a "no space" format for short flags but doesn't support auto complete for this case.
Related to issue #1629