From 35037705a90b61ac52a38f6f41ce48b071537143 Mon Sep 17 00:00:00 2001 From: Ophestra Date: Sun, 23 Feb 2025 02:02:01 +0900 Subject: command/flag: implement integer flag Signed-off-by: Ophestra --- command/flag.go | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'command/flag.go') diff --git a/command/flag.go b/command/flag.go index 5765dd0d..8e890a1a 100644 --- a/command/flag.go +++ b/command/flag.go @@ -28,6 +28,14 @@ func (v StringFlag) Define(b *strings.Builder, set *flag.FlagSet, p any, name, u b.WriteString(" [" + prettyFlag(name) + " ]") } +// IntFlag is the default value of an int flag. +type IntFlag int + +func (v IntFlag) Define(b *strings.Builder, set *flag.FlagSet, p any, name, usage string) { + set.IntVar(p.(*int), name, int(v), usage) + b.WriteString(" [" + prettyFlag(name) + " ]") +} + // BoolFlag is the default value of a bool flag. type BoolFlag bool -- cgit v1.3.1