From 614119b22dd6e1f84226abd9fd6e6b4a6821bd71 Mon Sep 17 00:00:00 2001 From: Roberto Hidalgo Date: Mon, 25 Sep 2023 19:08:23 -0600 Subject: [PATCH] return root on tree if found --- pkg/tree/tree.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/pkg/tree/tree.go b/pkg/tree/tree.go index 097915e..7076806 100644 --- a/pkg/tree/tree.go +++ b/pkg/tree/tree.go @@ -3,6 +3,7 @@ package tree import ( + "bytes" "sort" "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 func Build(cc *cobra.Command, depth int) { + root := registry.FromCobra(cc) + if root == nil && cc.Root() == cc { + root = command.Root + } tree = &CommandTree{ - Command: registry.FromCobra(cc), + Command: root, Children: []*CommandTree{}, } @@ -59,11 +64,11 @@ func Build(cc *cobra.Command, depth int) { } func Serialize(serializationFn func(any) ([]byte, error)) (string, error) { - bytes, err := serializationFn(tree) + content, err := serializationFn(tree) if err != nil { return "", err } - return string(bytes), nil + return string(bytes.ReplaceAll(content, []byte("﹅"), []byte("`"))), nil } func ChildrenNames() []string {