cli icon indicating copy to clipboard operation
cli copied to clipboard

can I remove default text when a flag's value is set

Open seyoatda opened this issue 4 years ago • 4 comments

seyoatda avatar May 27 '21 09:05 seyoatda

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

seyoatda avatar May 27 '21 10:05 seyoatda

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.

stale[bot] avatar Aug 25 '21 19:08 stale[bot]

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 avatar Oct 14 '21 14:10 Toady00

@Toady00 One thing I found you can do is set DefaultText: "" on the flag.

valorl avatar Nov 01 '21 15:11 valorl

@valorl's suggestion isn't working for me with a BoolFlag:

--help, -h                       Show help (default: false)
image

lorensr avatar Sep 23 '22 04:09 lorensr

@lorensr Can you check if this problem exists with latest release as well ? We've made some changes to default handling

dearchap avatar Oct 18 '22 23:10 dearchap

@dearchap I'm getting the same behavior on latest v2.23.7

lorensr avatar Dec 28 '22 00:12 lorensr

@lorensr can you post a code snippet ?

dearchap avatar Dec 28 '22 00:12 dearchap

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

lorensr avatar Dec 28 '22 00:12 lorensr

Can you set DefaultText to " " or a non empty string?

dearchap avatar Dec 28 '22 23:12 dearchap

Here is " ":

   --help, -h     Show help (default:  )

lorensr avatar Dec 29 '22 00:12 lorensr

Okay I see the issue now. So would you like to hide the default text only for bool flags or for all flags ?

dearchap avatar Dec 29 '22 02:12 dearchap

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 avatar Dec 29 '22 02:12 lorensr

@lorensr Can you try the PR and see if it works for you ? Thanks

dearchap avatar Dec 30 '22 16:12 dearchap

@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: "",
}

lorensr avatar Aug 03 '23 04:08 lorensr