Files
hakurei/command/node.go
T
cat f1dd3a085b
Test / Create distribution (push) Successful in 53s
Test / Sandbox (push) Successful in 2m51s
Test / Hakurei (push) Successful in 4m29s
Test / Sandbox (race detector) (push) Successful in 5m53s
Test / Hakurei (race detector) (push) Successful in 7m2s
Test / ShareFS (push) Successful in 7m19s
Test / Flake checks (push) Successful in 1m8s
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
}