Begin implementing the stringer for the todo node tree
This commit is contained in:
parent
2e514a4d9c
commit
0d546db344
2
main.go
2
main.go
|
@ -1,6 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"github.com/davecgh/go-spew/spew"
|
"github.com/davecgh/go-spew/spew"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -25,4 +26,5 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
spew.Dump(tf.FoundTable)
|
spew.Dump(tf.FoundTable)
|
||||||
|
fmt.Println(tf.foundTree.String())
|
||||||
}
|
}
|
||||||
|
|
39
node.go
39
node.go
|
@ -1,8 +1,15 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
|
type nodeType int
|
||||||
|
|
||||||
|
const (
|
||||||
|
DIR nodeType = iota
|
||||||
|
FILE
|
||||||
|
)
|
||||||
|
|
||||||
type node struct {
|
type node struct {
|
||||||
Name string
|
Name string
|
||||||
Type string
|
Type nodeType
|
||||||
Nodes []*node
|
Nodes []*node
|
||||||
Todos []*todo
|
Todos []*todo
|
||||||
}
|
}
|
||||||
|
@ -32,10 +39,34 @@ func (n *node) AddToTree(path []string, t *todo) {
|
||||||
nn.AddToTree(path[1:], t)
|
nn.AddToTree(path[1:], t)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n node) getTypeFromPath(path []string) string {
|
func (n node) getTypeFromPath(path []string) nodeType {
|
||||||
if len(path) == 1 {
|
if len(path) == 1 {
|
||||||
return "file"
|
return FILE
|
||||||
}
|
}
|
||||||
|
|
||||||
return "dir"
|
return DIR
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (n node) String() string {
|
||||||
|
return n.toString("", 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO there is some kind of bug with this. Fix
|
||||||
|
func (n node) toString(in string, indent int) string {
|
||||||
|
idnt := ""
|
||||||
|
for i := 0; i < indent; i++ {
|
||||||
|
idnt += " "
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, c := range n.Nodes {
|
||||||
|
switch c.Type {
|
||||||
|
case DIR:
|
||||||
|
in += idnt + "- " + c.Name + "\n"
|
||||||
|
in = n.toString(in, indent+1)
|
||||||
|
case FILE:
|
||||||
|
in += idnt + "- " + c.Name + "\n"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return in
|
||||||
|
}
|
|
@ -27,7 +27,7 @@ type TodoFinder struct {
|
||||||
func NewTodoFinder() (TodoFinder, error) {
|
func NewTodoFinder() (TodoFinder, error) {
|
||||||
tf := TodoFinder{
|
tf := TodoFinder{
|
||||||
FoundTable: []*todo{},
|
FoundTable: []*todo{},
|
||||||
foundTree: &node{Name: "root", Type: "dir"},
|
foundTree: &node{Name: "root", Type: DIR},
|
||||||
keywords: []string{"todo", "fixme"},
|
keywords: []string{"todo", "fixme"},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue