aboutsummaryrefslogtreecommitdiffhomepage
path: root/command/node.go
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2025-02-22 20:30:49 +0900
committerOphestra <cat@gensokyo.uk>2025-02-22 20:30:49 +0900
commit7bd48d34899e01d0dc3f0bfb042690f9ee0b1219 (patch)
tree1a4453f2a441fa4f92dff9b9a9e6c1a11487bf0f /command/node.go
parentb5eaeac11ab2dac0a6025c1666d5070fb64bff2e (diff)
command: implement node structure
Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'command/node.go')
-rw-r--r--command/node.go36
1 files changed, 36 insertions, 0 deletions
diff --git a/command/node.go b/command/node.go
new file mode 100644
index 00000000..9ed21499
--- /dev/null
+++ b/command/node.go
@@ -0,0 +1,36 @@
+package command
+
+import (
+ "flag"
+ "io"
+)
+
+type node struct {
+ child, next *node
+ name, usage string
+
+ out io.Writer
+ logf LogFunc
+
+ f HandlerFunc
+ set *flag.FlagSet
+}
+
+func (n *node) adopt(v *node) bool {
+ if n.child != nil {
+ return n.child.append(v)
+ }
+ n.child = v
+ return true
+}
+
+func (n *node) append(v *node) bool {
+ if n.name == v.name {
+ return false
+ }
+ if n.next != nil {
+ return n.next.append(v)
+ }
+ n.next = v
+ return true
+}