Files
hakurei/command/node.go
T
cat f1dd3a085b command: hard wrap help message flags
This greatly improves readability when lots of flags are registered.

Signed-off-by: Ophestra <cat@gensokyo.uk>
2026-08-07 20:32:24 +09:00

45 lines
697 B
Go

package command
import (
"flag"
"io"
)
// 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 []string
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
}