Build nodes with children and display them like the classic tree command shows dirs
Example
package main
import (
"fmt"
"github.com/rendicott/gree"
)
func main() {
a := gree.NewNode("root")
a.NewChild("child1").NewChild("grandchild1")
a.NewChild("child2").NewChild("grandchild2")
a.NewChild("child3").NewChild("grandchild3")
a.NewChild("child4")
a.NewChild("child5")
// add child to 1st grandchild of 2nd child of root
a.GetChild(1).GetChild(0).NewChild("whoops")
// integrate a new tree
b := gree.NewNode("extended")
b.NewChild("puppy1").NewChild("grandpuppy1")
b.NewChild("puppy2").NewChild("grandpuppy2")
a.GetChild(2).AddChild(&b)
fmt.Println(a.Draw())
}
Package gree provides a Node struct to which
children can be retrieved and added. Calling
the Draw() method on a Node returns the 'tree'
like string representation of the Node and its
children
Example:
func main() {
a := gree.NewNode("root")
a.NewChild("child1")
a.NewChild("child2").NewChild("grandchild1")
a.Draw()
}
NewChild adds a child with contents of the passed
string to this Node's children. It returns the pointer
to the new Node. This can be discarded or used for chaining
methods in literals (e.g., a.NewChild("foo").NewChild("bar"))