cli
cli copied to clipboard
can I remove default text when a flag's value is set
It seems that when I set a flag's value, the help info will show a default text , even if I do not try to set a default text hint.
for example, if I create a IntFlag, then its value is 0 as default, which is initialize by golang itself. then the default text is shown as (default: 0). But I didn't set the value as 0, and the default text was not supposed to show
This issue or PR has been automatically marked as stale because it has not had recent activity. Please add a comment bumping this if you're still interested in it's resolution! Thanks for your help, please let us know if you need anything else.
I have a similar issue I'm not sure how to handle. If I set an env var for a flag, say for a sensitive value like an api token, I don't want the help outputing that token as a "default" value if it's set in the environment at the time. How do I use the EnvVars flags without effecting the default help text?
@Toady00 One thing I found you can do is set DefaultText: "" on the flag.
@valorl's suggestion isn't working for me with a BoolFlag:
--help, -h Show help (default: false)
@lorensr Can you check if this problem exists with latest release as well ? We've made some changes to default handling
@dearchap I'm getting the same behavior on latest v2.23.7
@lorensr can you post a code snippet ?
cli.HelpFlag = &cli.BoolFlag{
Name: "help",
Aliases: []string{"h"},
Usage: "Show help",
DefaultText: "",
}
Setting DefaultText: "" does not remove the (default: false) output below:
--help, -h Show help (default: false)
Diff: https://github.com/temporalio/cli/compare/main...repro-1277 Repro: https://github.com/temporalio/cli/tree/repro-1277
Can you set DefaultText to " " or a non empty string?
Here is " ":
--help, -h Show help (default: )
Okay I see the issue now. So would you like to hide the default text only for bool flags or for all flags ?
Only for these two flags:
GLOBAL OPTIONS:
--help, -h show help (default: false)
--version, -v print the version (default: false)
and not for other bool flags or flags of other types.
@lorensr Can you try the PR and see if it works for you ? Thanks
@dearchap I'm on v2.25.7, and now by default I don't see (default: false). However, if I change show help to Show help with this, (default: false) comes back:
cli.HelpFlag = &cli.BoolFlag{
Name: "help",
Aliases: []string{"h"},
Usage: "Show help",
DefaultText: "",
}