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

flag: Unexpected print result from flag.PrintDefaults() with grave accent mark (`). #58921

Closed
dimandzhi opened this issue Mar 7, 2023 · 2 comments
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.

Comments

@dimandzhi
Copy link

dimandzhi commented Mar 7, 2023

Using grave accent mark (`) in descriptions to flags produces unexpected flag.PrintDefaults() results. In case of two grave accent marks used all between them are moved next to flag name to the previous row. The desired result is achieved using three grave accent marks in a row. Tested on 1.19 and 1.20.
Example:

desc := fmt.Sprintf("Place `foo` option, or maybe `bar`")
flag.StringVar(new(string), "missing", "something", desc)
desc = fmt.Sprintf("Place ```foo` option, or maybe `bar`")
flag.StringVar(new(string), "workaround", "something", desc)
flag.Parse()
flag.PrintDefaults()
// Result:
// -missing foo
//	Place foo option, or maybe `bar` (default "something")
// -workaround
//	Place `foo` option, or maybe `bar` (default "something")

AFAIK, this behavior is not documented.

@dimandzhi dimandzhi changed the title Unexpected print result from flag.PrintDefaults() with grave accent mark (`). flag: Unexpected print result from flag.PrintDefaults() with grave accent mark (`). Mar 7, 2023
@bcmills
Copy link
Contributor

bcmills commented Mar 7, 2023

AFAIK, this behavior is not documented.

https://pkg.go.dev/flag#PrintDefaults says:

The listed type … can be changed by placing a back-quoted name in the flag's usage string; the first such item in the message is taken to be a parameter name to show in the message and the back quotes are stripped from the message when displayed.

@ianlancetaylor ianlancetaylor added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Mar 7, 2023
@dimandzhi
Copy link
Author

Ah, I didn't quite understood what back-quoted name was, but example makes it clair. I should have been more attentive. Thank you for your time and sorry! Closing issue.

@golang golang locked and limited conversation to collaborators Mar 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

4 participants