-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Should I expect completion of nested command's flags to work? #1916
Comments
@ldelossa what release are you using ? |
Hey there @dearchap
So v3. You can see my code here: https://github.com/ldelossa/cmds/blob/main/main.go#L129 Tho its a bit funky, since I'm generating a command graph based off a yaml config. |
@ldelossa Its okay to generate the cmd graph from a yaml. I dont see any real issues with your implementation. It should work. You sourced the zsh completion script for this app correct ? Everytime you hit on the terminal for completion(for this app) the app will be run with the --generate-shell-completion arg so that the app can output the cmd/flags as needed. Have you tried putting this through a debugger to see whats going on ? |
@dearchap Here is a screencap of the issue, as you can see, I can not get tab completion for any flag hanging off the sub command 'automation' 2024-05-27T11.21.00-04.00.mp4I'm not sure how I can debug the simulation of hitting For example, I want my debugger to stop at the code that generates the shell completion, but only after I have the string Here is the output from just running the flag:
By the way, this is only a problem with flags, completion of arbitrarily nested sub-command names work fine. |
Are you sure I should be seeing completion for flags?
I think the above demonstrates clearly that no flags are being generated for completion. I debugged it a bit, but I never see the |
Here is a repo with a very lean reproduction: https://github.com/ldelossa/urfacecli_test Just
And try to perform autocompletion for the flag hanging off |
@ldelossa I tried out your lean code and it works for me. Are you in a zsh first of all ? also how are you invoking the program
|
Very interesting! Okay thank you for confirming this is an issue locally. I always invoke with ./main. But now, let me enter a zsh with absolute minimum config and see if it works. |
Okay @dearchap So I am on zsh 5.9 and this does not work. Here is an example on my system: 2024-05-30T15.44.59-04.00.mp4And here is the script:
|
Tried the same thing in a zsh 5.8 container:
|
Are you hitting TAB after the command and you see the subcommand ? If you hit the TAB after subcommand you should see h for help. The generate-shell-completion arg is automatically passed to the program when TAB is hit. You shouldn't need to type in --generate-shell-completion manually unless you are testing the autocomplete behavior . So what exactly is the problem here ? I'm confused |
I'm trying to get completion for the flag hanging off 'subcommand'. For instance if I do this:
I expect to see completion suggestions like this:
That was the original question created in the discussion topic. |
@ldelossa Ok I understand now. Yes looks like there is an issue. Let me see what I can do |
@ldelossa Can you do |
No problem @dearchap The output was very large so put it in a pastebin: https://pastebin.com/Y84QDy2h |
@ldelossa Are you typing "--" at the end ? Can you try "-" and then hit the tab ? |
@dearchap no problem, here's latest: https://pastebin.com/jtEf28Xt |
We seem to be going into |
@ldelossa Yes you're right. The code doesnt make sense. Something isnt right. v2 has the correct behaviour, we seem to have broken it in v3. I will put in a fix. Thanks for raising this issue |
No problem, looking forward to seeing it fixed :-D. Thanks for working with me on explaining this situation. |
If i comment out:
Things begin to work. Maybe this is a bad heuristic, since having defined flags does not necessary mean |
Unfortunately, your fix does not fix the issue. Like I mentioned above, the replacement of 'args' here:
Is breaking things. As soon as I do this:
Everything works. 2024-06-01T15.58.15-04.00.mp4 |
@ldelossa did you use the latest fix I just merged ? |
Yes, dont you see the code present in the video I just sent? That is latest. |
@ldelossa sorry yes I was reading the comments in my email and didnt watch the video. Let me dig into this a bit more. |
@ldelossa The problem is much more complex than I first thought. Can you try with latest code(without your changes) and try just "-" and TAB instead of "--" and TAB ? |
@dearchap yup, I tried both, both do not complete. |
@ldelossa if you comment out the args it might work with flags but will fail with subcommands.
|
Not for me. Everything works when i comment that out. This, i don't know about positional argument competition. I don't use that only flags |
@ldelossa can you try fix from latest PR ? Kind of kludgy but works |
hey @dearchap running out of cycles to keep testing this unfortunately, I provided the test example which should determine if your fixes work or not. I would just ensure to check for all tab completion "-", "--", arguments and subcommands. |
Discussed in #1915
Originally posted by ldelossa May 25, 2024
Hello,
I have a root command called 'cmd'.
Now I have a sub command hanging off this called "sub-command".
The cli.Command for "sub-command" defines 2 flags "--a, --b".
All commands have the "EnableShellCompletion" boolean set to true.
I'm using
zsh
. Should I expect to see completion forcmd subcommand --<Tab>
.My assumption was to see completion for
--a, --b
but instead the only completion I get is for--h, -help
essentially.The text was updated successfully, but these errors were encountered: