-
Notifications
You must be signed in to change notification settings - Fork 354
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
Document behavior of backticks in usage string #200
Comments
I would love if this behavior could be customized or turned off. I can't always control the usage messages in my CLI (long story short) and they often have back quotes that are not intended to be used this way. It's causing some confusion and it's a bummer that I can't just default to the "educated guess of the type of the flag's value". I looked through the code and don't see an easy or obvious way to implement that so all of to this to say: I'm offering a +1 for this being documented. At the very least, users should know that it's going to happen. |
👍 |
This commit copies the docs from the golang flag package to better explain the behavior of backticks in a flag's usage. Fixes spf13#200
This commit copies the docs from the golang flag package to better explain the behavior of backticks in a flag's usage. Fixes spf13#200
This commit copies the docs from the golang flag package to better explain the behavior of backticks in a flag's usage. Fixes spf13#200
This commit copies the docs from the golang flag package to better explain the behavior of backticks in a flag's usage. Fixes spf13#200
Backticks in a flag description have a special meaning, in both standard `flag` and the `pflag` package used here. Because of this, flag was described as: --inject-labels tk prune add tanka environment label to each created resource. Required for tk prune. Now it will look like: --inject-labels add tanka environment label to each created resource. Required for 'tk prune'. See spf13/pflag#200 Signed-off-by: Oleg Zaytsev <[email protected]>
Backticks in a flag description have a special meaning, in both standard `flag` and the `pflag` package used here. Because of this, flag was described as: --inject-labels tk prune add tanka environment label to each created resource. Required for tk prune. Now it will look like: --inject-labels add tanka environment label to each created resource. Required for 'tk prune'. See spf13/pflag#200 Signed-off-by: Oleg Zaytsev <[email protected]>
Prefious: ``` --persistent-keepalive PersistentKeepalive WireGuard PersistentKeepalive for the SORACOM Arc server, which will override arc.json#persistentKeepalive value (default 60) ``` Corrected: ``` --persistent-keepalive int WireGuard "PersistentKeepalive" for the SORACOM Arc server, which will override arc.json#persistentKeepalive value (default 60) ``` This because of the `pflag` package trick; that package extracts the back-quoted word from the usage text and guess/use that word as the type of value. ref: spf13/pflag#200 This might come from the original golang's flag package: > 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 > https://pkg.go.dev/flag#PrintDefaults So this patch replaces the back-quotes with double-quotes to avoid the unexpected behavior. Signed-off-by: moznion <[email protected]>
Previous: ``` --persistent-keepalive PersistentKeepalive WireGuard PersistentKeepalive for the SORACOM Arc server, which will override arc.json#persistentKeepalive value (default 60) ``` Corrected: ``` --persistent-keepalive int WireGuard "PersistentKeepalive" for the SORACOM Arc server, which will override arc.json#persistentKeepalive value (default 60) ``` This is because of the `pflag` package trick; that package extracts the back-quoted word from the usage text and guesses/uses that word as the type of value. ref: spf13/pflag#200 This might come from the original golang's flag package: > 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 > https://pkg.go.dev/flag#PrintDefaults So this patch replaces the back-quotes with double-quotes to avoid the unexpected behavior. Signed-off-by: moznion <[email protected]>
Pflag changes the type of a flag to match a string in back quotes in the usage string. For example, if flag "test" had usage message "this sets up the
testtype
variable", the output would be:This is unexpected behavior and is also not documented anywhere except in this godoc for the
UnquoteUsage
function: https://godoc.org/github.com/spf13/pflag#UnquoteUsageThis should be documented somewhere more visibly as back quotes are commonly used in descriptions and usage text.
The text was updated successfully, but these errors were encountered: