Files
hakurei/command/node.go
T
cat b37c1d8993
Test / Create distribution (push) Successful in 52s
Test / Sandbox (push) Successful in 2m51s
Test / Hakurei (push) Successful in 4m44s
Test / Sandbox (race detector) (push) Successful in 5m46s
Test / Hakurei (race detector) (push) Successful in 7m5s
Test / ShareFS (push) Successful in 7m5s
Test / Flake checks (push) Successful in 1m8s
command: use NUL for magic usage string
This change also improves documentation.

Signed-off-by: Ophestra <cat@gensokyo.uk>
2026-08-07 18:57:01 +09:00

46 lines
715 B
Go

package command
import (
"flag"
"io"
"strings"
)
// A node represents a command.
type node struct {
child, next *node
name, usage string
out io.Writer
logf LogFunc
// Names of commands preceding node.
prefix []string
// Short user-facing representations of flags received by node.
suffix strings.Builder
f HandlerFunc
set *flag.FlagSet
}
// adopt adds v as the last child of n.
func (n *node) adopt(v *node) bool {
if n.child != nil {
return n.child.append(v)
}
n.child = v
return true
}
// append adds v as the last sibling of n.
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
}