command: implement node structure
Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
parent
b5eaeac11a
commit
7bd48d3489
36
command/node.go
Normal file
36
command/node.go
Normal file
@ -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
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user