Skip to content
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

Square brackets in the description causes problems with zsh #1129

Closed
umbynos opened this issue May 27, 2020 · 5 comments
Closed

Square brackets in the description causes problems with zsh #1129

umbynos opened this issue May 27, 2020 · 5 comments

Comments

@umbynos
Copy link
Contributor

umbynos commented May 27, 2020

I think I found a bug with zsh completion in cobra 1.0.0: If I put square brackets in a command description they do not get escaped correctly causing problems.
Here there's an example of the line causing problems.
I "patched" this behaviour with:

buf := new(bytes.Buffer)
	cmd.Root().GenZshCompletion(buf)
	r := strings.NewReplacer("[", "\\[", "]", "\\]") //insert escaping before [ and ]
	s := r.Replace(buf.String())
	s = strings.ReplaceAll(s, "\\[1\\]", "[1]") // revert the case
	os.Stdout.WriteString(s)

I think this will be fixed in #1070 but I'm opening that just for reference

@marckhouzam
Copy link
Collaborator

I just realized this is a duplicate of #899.
And I can confirm the problem is not present with #1070.

@bufdev
Copy link

bufdev commented Jul 13, 2020

This seems to be a problem if you have brackets in the flag line, and I can't figure out how to mitigate this. For example:

--log-format string   The log format [text,color,json]. (default "color")

This causes an issue. How would you mitigate this using #1070?

@marckhouzam
Copy link
Collaborator

This causes an issue. How would you mitigate this using #1070?

Hi @bufdev, #1070 will fix this problem automatically, nothing special for you to do. However, #1070 is not yet part of an official Cobra release, which is why it is not working for you.

You could choose to point your go.mod file to a more recent commit of the Cobra repo if you really want to get access to #1070 right away; or else, you will need to wait for the next Cobra release.

@bufdev
Copy link

bufdev commented Jul 13, 2020

Ah perfect! Thank you so much, makes sense!

@marckhouzam
Copy link
Collaborator

@jpmcb I believe we can close this one now that #1070 has been merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants