aboutsummaryrefslogtreecommitdiffhomepage
path: root/command/flag.go
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2025-02-23 02:02:01 +0900
committerOphestra <cat@gensokyo.uk>2025-02-23 02:02:01 +0900
commit35037705a90b61ac52a38f6f41ce48b071537143 (patch)
tree038bf98230b4a603e2e4a4be397ebeb369fbef2e /command/flag.go
parent647c6ea21baa28192e5c4339ed4cdf83e994036e (diff)
command/flag: implement integer flag
Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'command/flag.go')
-rw-r--r--command/flag.go8
1 files changed, 8 insertions, 0 deletions
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) + " <value>]")
}
+// 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) + " <int>]")
+}
+
// BoolFlag is the default value of a bool flag.
type BoolFlag bool