-
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
Zsh Completion #646
Zsh Completion #646
Conversation
A very basic POC. Need to refactor to generate completion structure before passing to the template to avoid repeated computations. What works: * Real zsh completion (not built on bash) * Basic flags (with long flag and optional shorthand) * Basic filename completion indication (not with file extensions though) What's missing: * File extensions to filename completions * Positional args * Do we require handling only short flags?
cmd.Use is not the command name :). Found it once I figured out that I need to execute the command in order to fully test the generated completion.
Also make the template more elegant on the way...
- removed redundant function - improved other functions :) - better names for other functions
- If the flags are not bool the completion expects argument. - You don't have to specify file extensions for file completion to work. - Allow multiple occurrences of flag if type is stringArray. Need to verify that these assumption are correct :)
They were committed by mistake.
Fixed after input from @eparis: - Decide on option parameter by checking NoOptDefVal - Slices also could be specified multiple times.
Yet another temporary file that found itself in the repo :(
I thought there was a bug in the boolSlice definition but it seems It was my mistake in identifying what's going on. Also removed the provisioning to skip tests (doesn't seem to be needed anymore).
I encountered an issue (with a utility that I write) that affect completion. Not sure if/how to solve this issue. I have a Should I at least point it out in the zsh completion readme? |
Does that mean that --help doesn't show up either? Do we want to make those late flag init calls a function, which we explicitly call from the generator command tree walk code? |
You're right about the |
@eparis, it seems that the whole |
It was running on the command it was invoked from which caused some additional helpers (--help, --version) not to be generated.
There's something really strange here. On my tests (last commit: 70f3e35) it behaves correctly but on my real command that I'm using it doesn't. damn. |
When invoking from subcommand. Modified the test to prove.
Ok, sadly the problem still exist. The problem was in my test. Added a skipped test to show real issue. Back to square one in terms of dealing with |
I tried your patch for rclone, and it seems much more complete! I believe single quotes It seems that all subcommands (e.g. |
Thanks for the input @breunigs, Do you have your changes committed in a branch or should I just try modifying master? I'll try to check it later today. |
Oh, rclone vendors cobra and updates its dependencies at the start of a new development cycle, so I can’t really commit that. It‘s enough to update the file (https://github.com/ncw/rclone/blob/master/vendor/github.com/spf13/cobra/zsh_completions.go), then run something like this:
```
go build && sudo rclone genautocomplete zsh
```
… On 17. Mar 2018, at 15:38, Haim Ashkenazi ***@***.***> wrote:
Thanks for the input @breunigs, Do you have your changes committed in a branch or should I just try modifying master? I'll try to check it later today.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
ברוך דיין האמת |
@babysnakes as much as I would like to see your work land in Cobra, please take all the time you need. Don't feel obligated to work on it if you don't feel like it. |
…#1967) ## Why ? I'm using Zsh (and I'm not the only one 🤣). Pulumi having Zsh completions is great. I will also add completions to the Homebrew Formula when this is merged. ## Why not use Cobra `GenZshCompletion` It's currently not good enough. Maybe it will be when spf13/cobra#646 is done. ## Implementation I did the same thing `kubectl` does for Zsh completion. Meaning using the bash completion generated by Cobra and adapting it to a zsh format. The resulting zsh completion file is not perfect (compared to one's where you have a short command description in the output) but it's good enough I think. I also changed the file output to a stdout output. I think it's better than outputting to a file and it will make adding completions in Homebrew straightforward. I don't know if the previous `gen-bash-completion` is used in any Pulumi project so this may break things.
Thank you for your work. Even though it's not merged yet, your code is already incredibly useful for generating completion definitions, storing them as an asset, and amending them manually. I noticed one small issue so far. When usage string contains multiple lines, descriptions looks very broken, even though |
Awesome work. |
Any updates on this? |
Hi @hoshsadiq and everyone else. Sorry for disappearing but I can't seem to find enough time to get into bash-completion (and I can't merge the completion of zsh and bash without it). I'm pretty fluent with zsh completion, but I tried several times already to understand how bash-completion works and I didn't manage to figure it out in the very limited time I had. The good news is that I found a team member who is ready to help so I hope to sync him on the status and hopefully he'll manage to take it further. |
There's also a forked version of this at github.com/rstuebe/cobra which is now being used by github.com/zaquestion/lab. So it would be good to do a fair bit of merging when it's feasible... |
Can't we get this merged somehow? I don't really understand whats the hold-up with bash completion since this targets the zsh completion and i don't expect it to solve everything at once. I would rather like to see this merged in the current state and fixes be done in succeeding smaller MR's than having it lying around another year. |
Maybe a temporary alternative until the PR is merged: https://github.com/rsteube/cobra-zsh-gen I extracted the zsh_completions.go changes and added a simple wrapper struct. import zsh "github.com/rsteube/cobra-zsh-gen
zsh.Wrap(RootCmd).GenZshCompletion(os.Stdout) example: zaquestion/lab@master...rsteube:use-cobra-zsh-gen It's a bit crude but seems to work so far. |
Thanks @rsteube Maybe this issue will get a bit more visibility with macOS switching to ZSH |
@babysnakes @eparis Thanks for this great contribution. Sorry I sat on things for such a long time. I'm trying to be a better steward. Merging 👍 |
Hey @spf13, I wasn't available for a few days. Thank you for merging it. Sadly, I'm not sure it was fully ready yet. I phased out of it when I realised I couldn't get any support with merging bash completion with zsh completion. I tried to find someone from work to help but it didn't work as well. In any case, I'm still ready to do the work on the Thanks |
Can you remind me why this affects bash completion? If you are aiming for a unified completion code, that's very much worth a separate PR IMHO. As a first step, we should get zsh completion right. @babysnakes What in your opinion is missing to make it fully ready? |
@corneliusweig, my original idea was to get something working (that was many months ago). One of the first feedbacks I got (which I completely agree with) is that we better merge the completions so users will not have to work hard on configuring bash and zsh separately. I actually did the first steps (on my laptop, never committed it - check the long thread to see why) but really got stuck at trying to figure out bash completion. The problem with merging this pull request before merging the completions is that now we have to worry about 3 APIs to be backward compatible (bash, zsh and unified). |
I improved the existing zsh completion with support for flags and some of the custom completion commands from bash completion. A description of what's supported could be found i the zsh completion readme. Thanks to everyone in the #107 thread for their help, especially to @eparis for explaining things to me over and over again ...
One important note is that I only tested it on a small project on my laptop. It needs to be tested on a larger project and more important on other people's shell configurations to make sure it works correctly.