return root on tree if found
This commit is contained in:
parent
d3e5afbdfc
commit
614119b22d
|
@ -3,6 +3,7 @@
|
||||||
package tree
|
package tree
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
"git.rob.mx/nidito/chinampa/internal/registry"
|
"git.rob.mx/nidito/chinampa/internal/registry"
|
||||||
|
@ -31,8 +32,12 @@ func (t *CommandTree) Traverse(fn func(cmd *command.Command) error) error {
|
||||||
var tree *CommandTree
|
var tree *CommandTree
|
||||||
|
|
||||||
func Build(cc *cobra.Command, depth int) {
|
func Build(cc *cobra.Command, depth int) {
|
||||||
|
root := registry.FromCobra(cc)
|
||||||
|
if root == nil && cc.Root() == cc {
|
||||||
|
root = command.Root
|
||||||
|
}
|
||||||
tree = &CommandTree{
|
tree = &CommandTree{
|
||||||
Command: registry.FromCobra(cc),
|
Command: root,
|
||||||
Children: []*CommandTree{},
|
Children: []*CommandTree{},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,11 +64,11 @@ func Build(cc *cobra.Command, depth int) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func Serialize(serializationFn func(any) ([]byte, error)) (string, error) {
|
func Serialize(serializationFn func(any) ([]byte, error)) (string, error) {
|
||||||
bytes, err := serializationFn(tree)
|
content, err := serializationFn(tree)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
return string(bytes), nil
|
return string(bytes.ReplaceAll(content, []byte("﹅"), []byte("`"))), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func ChildrenNames() []string {
|
func ChildrenNames() []string {
|
||||||
|
|
Loading…
Reference in New Issue