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

Document behavior of backticks in usage string #200

Open
AlexNPavel opened this issue Jan 25, 2019 · 2 comments · Fixed by cornfeedhobo/pflag#4
Open

Document behavior of backticks in usage string #200

AlexNPavel opened this issue Jan 25, 2019 · 2 comments · Fixed by cornfeedhobo/pflag#4

Comments

@AlexNPavel
Copy link

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:

      --test testtype  this sets up the testtype variable

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#UnquoteUsage

This should be documented somewhere more visibly as back quotes are commonly used in descriptions and usage text.

@dpopp07
Copy link

dpopp07 commented Sep 17, 2020

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.

@IzhakJakov
Copy link

👍

cornfeedhobo added a commit to cornfeedhobo/pflag that referenced this issue Mar 10, 2021
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
cornfeedhobo added a commit to cornfeedhobo/pflag that referenced this issue Mar 10, 2021
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
cornfeedhobo added a commit to cornfeedhobo/pflag that referenced this issue Mar 11, 2021
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
cornfeedhobo added a commit to cornfeedhobo/pflag that referenced this issue Mar 12, 2021
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
colega added a commit to grafana/tanka that referenced this issue Mar 31, 2022
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 <mail@olegzaytsev.com>
julienduchesne pushed a commit to grafana/tanka that referenced this issue Mar 31, 2022
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 <mail@olegzaytsev.com>
moznion added a commit to soracom/soratun that referenced this issue Aug 30, 2022
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 <moznion@mail.moznion.net>
moznion added a commit to soracom/soratun that referenced this issue Aug 30, 2022
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 <moznion@mail.moznion.net>
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

Successfully merging a pull request may close this issue.

3 participants