-
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
feat: add CompletionWithDesc helper #2231
Conversation
6ee0588
to
5345ce2
Compare
My only hesitation about making this change is that programs that want to use the new type alias will need to replace Would |
The type alias is not required. But I get your point. IDE or AI tool will complete it this way I think cobra.Completion is clear enough. But then, we also move to cobra.CompletionWithDescription ? I'm fine with CompletionWithDescription and CompletionWithDesc What would be your choice? |
OK for cobra.Completion |
277becc
to
8499067
Compare
The code has also been refactored to use a type alias for completion and a completion helper Using a type alias is a non-breaking change and it makes the code more readable and easier to understand. Signed-off-by: ccoVeille <3875889+ccoVeille@users.noreply.github.com>
Co-authored-by: Marc Khouzam <marc.khouzam@gmail.com> Signed-off-by: ccoVeille <3875889+ccoVeille@users.noreply.github.com>
Signed-off-by: ccoVeille <3875889+ccoVeille@users.noreply.github.com>
Co-authored-by: Marc Khouzam <marc.khouzam@gmail.com> Signed-off-by: ccoVeille <3875889+ccoVeille@users.noreply.github.com>
8499067
to
8bcda5b
Compare
The completion should be tested also in a mode that returns the description Co-authored-by: Marc Khouzam <marc.khouzam@gmail.com> Signed-off-by: ccoVeille <3875889+ccoVeille@users.noreply.github.com>
I tried this with I went ahead and used your new |
Signed-off-by: Marc Khouzam <marc.khouzam@gmail.com>
I've just pushed a commit to use the new type alias and function everywhere. |
I'm more than fine with the changes, you did. I love the way how it somehow shows the changed was not only a good thing, but needed. |
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.
Very nice!
Thanks!
From what I can see Go can handle the conversion between the original The same goes for the type defined by the docker CLI: The problem happens because now we are asking go to accept the type Cobra should not break programs, so we should fix this in Cobra; who knows how many other programs use their own type for the completion functions. We could simply revert and not define What do people think? I haven't used type aliases much so I don't have a good feel for it. |
Thank you @marckhouzam for the investigation Sorry for the inconvenience @thaJeztah or anyone who may have face this issue. I thibk the issue is in fact related to #2220 where CompletionFunc was added The changes in the current PR and #2220 were released at same time. I think the solution of using a type alias for CompletionFunc so adding an alias is a good one. I'm surprised the problem was not covered by a test, I can add one. I would recommend to retract 1.9.0 for now via a 1.9.1 But the fix seems easy. So let's try to fix it |
Thanks both! Sorry for my rather brief comment earlier; I saw the issue reported and only had time to dive in for a tiny bit because I had to head out. I'm not sure how widely spread the problem is; if the issue is purely in our specific situation or more widespread. At least I saw that part of the issue on our side is that we define a I suspect that fixing on our side would not be too complicated and could possibly be limited to just that (aliasing our Looking at the comment, I see it was mostly done to create a "pseudo" type to make for a nicer documentation;
I've done similar tricks in some cases for the same reason, and most of the time it works without issues, but there's definitely been cases where it's slightly more involved or not possible without breaking things (unfortunately!). So .. possibly changing back the type CompletionFunc func(cmd *Command, args []string, toComplete string) (completion []string, _ ShellCompDirective)
Ah, possibly that sounds plausible as well, and possibly could also explain why we have that local |
I did a quick test, and it seems that making the (I asked @tassa-yoniso-manasi-karoto, who reported the issue (thanks!!) to verify if that approach works) |
Thanks for your note @thaJeztah I managed to understand the issue. I confirm adding the type alias as @marckhouzam suggested fixes the issue. I managed to replicate the issue locally. I'm working on a fix. |
Awesome, thank you! And no stress (please!) the world didn't burn because of this, and it was great to be discovered this soon after the release. |
Here is the fix |
The code has also been refactored to use a type alias for completion and a completion helper
Using a type alias is a non-breaking change, and it makes the code more readable and easier to understand.
Fixes #2222