aboutsummaryrefslogtreecommitdiff
path: root/func_test.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 /func_test.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 'func_test.go')
-rw-r--r--func_test.go30
1 files changed, 30 insertions, 0 deletions
diff --git a/func_test.go b/func_test.go
index 9be74fa..d492b48 100644
--- a/func_test.go
+++ b/func_test.go
@@ -151,3 +151,33 @@ func TestFuncCompat(t *testing.T) {
}
})
}
+
+func TestFuncUsage(t *testing.T) {
+ t.Run("regular func flag", func(t *testing.T) {
+ // regular func flag:
+ // expect to see '--flag1 value' followed by the usageMessage, and no mention of a default value
+ fset := NewFlagSet("unittest", ContinueOnError)
+ fset.Func("flag1", "usage message", func(s string) error { return nil })
+ usage := fset.FlagUsagesWrapped(80)
+
+ usage = strings.TrimSpace(usage)
+ expected := "--flag1 value usage message"
+ if usage != expected {
+ t.Fatalf("unexpected generated usage message\n expected: %s\n got: %s", expected, usage)
+ }
+ })
+
+ t.Run("func flag with placeholder name", func(t *testing.T) {
+ // func flag, with a placeholder name:
+ // if usageMesage contains a placeholder, expect that name; still expect no mention of a default value
+ fset := NewFlagSet("unittest", ContinueOnError)
+ fset.Func("flag2", "usage message with `name` placeholder", func(s string) error { return nil })
+ usage := fset.FlagUsagesWrapped(80)
+
+ usage = strings.TrimSpace(usage)
+ expected := "--flag2 name usage message with name placeholder"
+ if usage != expected {
+ t.Fatalf("unexpected generated usage message\n expected: %s\n got: %s", expected, usage)
+ }
+ })
+}