-
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
Make sure we quote brackets when generating zsh completion #899
Make sure we quote brackets when generating zsh completion #899
Conversation
CLA link doesnt seem to work 😢 |
I am not really sure why unittest fails, the spellchecking is only done on bash_completion |
#889 has been merged into master. A rebase will fix the tests. |
12df56c
to
4720dca
Compare
thanks for the heads up i rebased! |
4720dca
to
03691be
Compare
@umarcor sure! Done. |
I guess that's ready for merge now, isntit ? |
We use a forked version of cobra on `github.com/chmouel/cobra@zsh-completion-fixes` which includes two patches that hasn't been merged : spf13/cobra#884 spf13/cobra#899 hopefully this won't needed when those issues gets merged. Signed-off-by: Chmouel Boudjnah <[email protected]>
We use a forked version of cobra on `github.com/chmouel/cobra@zsh-completion-fixes` which includes two patches that hasn't been merged : spf13/cobra#884 spf13/cobra#899 hopefully this won't needed when those issues gets merged. Signed-off-by: Chmouel Boudjnah <[email protected]>
Fixes knative#426 and a couple of patches on top which aren't merged yet - spf13/cobra#884 - spf13/cobra#899
Can we get this merged, please ? The changes look reasonable simple and valid (and it also bites us for our ZSH completion business). Thanks ! |
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.
Thanks Chmouel!
Can we get this merged please?
It should help us vendor cobra from master branch commit after merge (since the next cobra milestone is Dec 20).
Fixes knative#426 and a couple of patches on top which aren't merged yet - spf13/cobra#884 - spf13/cobra#899
Fixes knative#426 - and a couple of patches on top which aren't merged yet - spf13/cobra#884 - spf13/cobra#899 - also updates viper to 1.4.0
Fixes knative#426 - and a couple of patches on top which aren't merged yet - spf13/cobra#884 - spf13/cobra#899 - also updates viper to 1.4.0
* Updates spf13/cobra dep to v0.0.5 Fixes #426 - and a couple of patches on top which aren't merged yet - spf13/cobra#884 - spf13/cobra#899 - also updates viper to 1.4.0 * Updates to go.sum * Updates go.mod as a result of `go install golang.org/x/tools/cmd/goimports`
@chmouel Can you please include the following patch in your PR to fix #989 : diff --git zsh_completions.go zsh_completions.go
index b58a5d6..e2476b6 100644
--- zsh_completions.go
+++ zsh_completions.go
@@ -25,6 +25,7 @@ var (
"extractFlags": zshCompExtractFlag,
"genFlagEntryForZshArguments": zshCompGenFlagEntryForArguments,
"extractArgsCompletions": zshCompExtractArgumentCompletionHintsForRendering,
+ "escapeText": zshCompQuoteFlagDescription,
}
zshCompletionText = `
{{/* should accept Command (that contains subcommands) as parameter */}}
@@ -41,7 +42,7 @@ function {{$cmdPath}} {
case $state in
cmnds)
commands=({{range .Commands}}{{if not .Hidden}}
- "{{.Name}}:{{.Short}}"{{end}}{{end}}
+ "{{.Name}}:{{.Short | escapeText}}"{{end}}{{end}}
)
_describe "command" commands
;;
@@ -334,5 +335,7 @@ func zshCompFlagCouldBeSpecifiedMoreThenOnce(f *pflag.Flag) bool {
func zshCompQuoteFlagDescription(s string) string {
return strings.NewReplacer("'", `'\''`,
"[", `\[`,
- "]", `\]`).Replace(s)
+ "]", `\]`,
+ "$(", `\$(`,
+ ).Replace(s)
}
diff --git zsh_completions_test.go zsh_completions_test.go
index 8079f6c..a9405fe 100644
--- zsh_completions_test.go
+++ zsh_completions_test.go
@@ -240,6 +240,25 @@ func TestGenZshCompletion(t *testing.T) {
`--ptest\[ptest]:filename:_files -g "-\(/\)"`,
},
},
+ {
+ name: "escape text in subcommand description",
+ root: func() *Command {
+ r := &Command{
+ Use: "rootcmd",
+ Long: "Long rootcmd description",
+ }
+ d := &Command{
+ Use: "subcmd1",
+ Short: "$(echo foo)",
+ Run: emptyRun,
+ }
+ r.AddCommand(d)
+ return r
+ }(),
+ expectedExpressions: []string{
+ `\$\(echo foo\)`,
+ },
+ },
}
for _, tc := range tcs { |
Hello @corneliusweig, I could surely do but what is the point if maints does not seem to want to merge this ? |
@chmouel I think a new release is due in December and PRs are usually merged shortly before that. But clearly, the maintainers have other responsibilities so lets bundle these improvements in a single PR. |
@corneliusweig sure, let's hope this gets merged, I have updated the PR, thanks |
This PR is being marked as stale due to a long period of inactivity |
I don't think this PR should be considered stale. |
@rhuss >70% of the open issues are already labeled as 'kind/stale' and it seems not possible to tell the bot otherwise. I believe it is a misconfiguration. |
@umarcor If the bot doesn't obey, just do a |
@corneliusweig, are you sure about that? That's what I would expect from any regular bot that handles stale issues. Some do also detect edition of comments, so it is not even required to force-push (any participant can help). However, the bot that is being used in this repo seems not to unmark anything: https://github.com/actions/stale. Unfortunately, most of the actions in https://github.com/actions feel like placeholders for marketing purposes. Some months will be required until quality catches up. See #952 (comment). |
No, I'm not sure. I was merely guessing. But have you tried? I'm curious what will happen 😄 |
I preventively ensured that all the PRs I proposed are updated and have a recent comment: https://github.com/spf13/cobra/pulls?q=is%3Apr+is%3Aopen+sort%3Aupdated-desc+author%3Aumarcor 😄 |
I gave up updating this PR, afer eight months being hopeful the maintainers just don't seem to care about those fixes |
which includes the zsh completion fix for spf13/cobra#899 and remove the fork of cobra with fix in `replace` section of go.mod
@marckhouzam : Thanks for the fix! Noticed a difference in the way auto-completion of flags starting with With the patch in this PR #899 , it also allows to auto-complete the flags, for eg:
would add
While if I try using #1070, and [tab] after
gives
while if I type So the difference is, this patch also takes care of auto-completing the flags, while #1070 would add Reproduce:
|
@navidshaikh Thank you for trying the new zsh completion early, it will help confirm there is no issues.
This change is on purpose to align it with bash-completion behaviour. It is important that shell-completion behaves the same across all shells, so we had to make this change since bash completion only completes flags if the user types the first I realize now that I didn't document it in: https://github.com/spf13/cobra/blob/master/zsh_completions.md
This is not right.
You'll notice that two
you will notice the extra From what I can see, I believe this is what is causing the extra Could you give more information about that? |
I had to make a documentation PR for something else, so I did this also. See #1169. |
@marckhouzam : thank you for debugging this! For example: |
Of course, there might be a better way to let cobra parse the arguments without temporarily creating a command. If so, please let us know. |
I'm not sure if it's the best way, but this seems to strip all the flags and their values and leaves you with args only:
|
Yeah, that's probably the right way - i used |
Thanks @marckhouzam @rsteube for the help! we could remove the extra command execution and use inbuilt parsing utils, and the extra directive /
Is it shell-completion limitation to have |
No, as far as i know that depends how you configure it. I think cobra had something like a |
I believe @rsteube has explained things very well. Here is the doc for marking a flag "required": https://github.com/spf13/cobra/blob/master/shell_completions.md |
Whoops, more precise URL for required flags |
* Pin spf13/cobra dep at b95db644ed1c0e183a90d8509ef2f9a5d51cc29b which includes the zsh completion fix for spf13/cobra#899 and remove the fork of cobra with fix in `replace` section of go.mod * Parse args without invoking a separate command Do not define and execute extractCommand before running actual root command to parse all the args without flags. This was creating issues with completion utils to generate additional shell completion directive. Now uses cobra's inbuilt utilities to parse the command args without flags. * Return error from stripFlags if any * Update unit tests
zsh completion would fail when we have brackets in description, for example :