aboutsummaryrefslogtreecommitdiffhomepage
path: root/command/command.go
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2025-02-22 20:21:57 +0900
committerOphestra <cat@gensokyo.uk>2025-02-22 20:29:47 +0900
commitb5eaeac11ab2dac0a6025c1666d5070fb64bff2e (patch)
tree6fe293a19ebc59f6c32980db286ea2b1b08be720 /command/command.go
parenta9986aab6a00cd08bc9beed38b506134dc525e3b (diff)
command: declare command interface
Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'command/command.go')
-rw-r--r--command/command.go34
1 files changed, 34 insertions, 0 deletions
diff --git a/command/command.go b/command/command.go
new file mode 100644
index 00000000..79833b32
--- /dev/null
+++ b/command/command.go
@@ -0,0 +1,34 @@
+// Package command implements generic nested command parsing.
+package command
+
+import "flag"
+
+type (
+ // HandlerFunc is called when matching a directly handled subcommand tree.
+ HandlerFunc = func(args []string) error
+
+ // LogFunc is the function signature of a printf function.
+ LogFunc = func(format string, a ...any)
+
+ // FlagDefiner is a deferred flag definer value, usually encapsulating the default value.
+ FlagDefiner interface {
+ // Define defines the flag in set.
+ Define(set *flag.FlagSet, p any, name, usage string)
+ }
+
+ Command interface {
+ Parse(arguments []string) error
+ baseNode[Command]
+ }
+ Node baseNode[Node]
+
+ baseNode[T any] interface {
+ // Command appends a subcommand with direct command handling.
+ Command(name, usage string, f HandlerFunc) T
+ // Flag defines a generic flag type in Node's flag set.
+ Flag(p any, name string, value FlagDefiner, usage string) T
+
+ // New returns a new subcommand tree.
+ New(name, usage string) (sub Node)
+ }
+)