aboutsummaryrefslogtreecommitdiff
path: root/flag.go
diff options
context:
space:
mode:
authorGeorges Varouchas <[email protected]>2025-06-09 22:38:23 +0400
committerGeorges Varouchas <[email protected]>2025-06-09 23:14:57 +0400
commit4730aa0d979f34d4f7427d524b84043557ba72ef (patch)
tree1216ad677454c2ffba6da37299a473a2296d5b98 /flag.go
parentf4c97c2487b06cff392d2958534e7195f79847fb (diff)
fix help message for Func and BoolFunc flags #430
* have '.Type()' for boolfuncValue return "boolfunc" (dedicated value, which now makes it distinct from funcValue) * hide extra "(default )" by stating that "" should be treated as a zero value for a boolFlag note: - a boolfuncValue matches 'case boolFlag:', as it implements the boolFlag interface, - treating "" as a value which shouldn't trigger a "(default )" for a regular Bool flag does not look like a breaking change * hide extra "[=something]" for boolfuncValue * set default placeholder name for "boolfunc" and "func" flag types
Diffstat (limited to 'flag.go')
-rw-r--r--flag.go8
1 files changed, 5 insertions, 3 deletions
diff --git a/flag.go b/flag.go
index 0b5be7a..d4dfbc5 100644
--- a/flag.go
+++ b/flag.go
@@ -549,7 +549,7 @@ func (f *FlagSet) PrintDefaults() {
func (f *Flag) defaultIsZeroValue() bool {
switch f.Value.(type) {
case boolFlag:
- return f.DefValue == "false"
+ return f.DefValue == "false" || f.DefValue == ""
case *durationValue:
// Beginning in Go 1.7, duration zero values are "0s"
return f.DefValue == "0" || f.DefValue == "0s"
@@ -599,8 +599,10 @@ func UnquoteUsage(flag *Flag) (name string, usage string) {
name = flag.Value.Type()
switch name {
- case "bool":
+ case "bool", "boolfunc":
name = ""
+ case "func":
+ name = "value"
case "float64":
name = "float"
case "int64":
@@ -718,7 +720,7 @@ func (f *FlagSet) FlagUsagesWrapped(cols int) string {
switch flag.Value.Type() {
case "string":
line += fmt.Sprintf("[=\"%s\"]", flag.NoOptDefVal)
- case "bool":
+ case "bool", "boolfunc":
if flag.NoOptDefVal != "true" {
line += fmt.Sprintf("[=%s]", flag.NoOptDefVal)
}