-
Notifications
You must be signed in to change notification settings - Fork 0
/
ki.go
52 lines (45 loc) · 920 Bytes
/
ki.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package main
import (
"flag"
"fmt"
"log/slog"
"os"
"path/filepath"
"strings"
"deedles.dev/ki"
)
func printTree(t *ki.Tree, depth int) {
var pre string
if depth >= 0 {
pre = strings.Repeat(" ", depth)
}
if t.Name() != "" {
fmt.Printf("%v%v\n", pre, t.Name())
}
t.Children(func(c *ki.Tree) bool {
printTree(c, depth+1)
return true
})
}
func main() {
flag.Usage = func() {
arg0 := filepath.Base(os.Args[0])
fmt.Fprintf(os.Stderr, "Usage: %v <paths...>\n", arg0)
fmt.Fprintf(os.Stderr, " command-producing-paths | %v [paths...]\n", arg0)
fmt.Fprintf(os.Stderr, " %v [paths...] < file-with-list-of-paths\n", arg0)
}
flag.Parse()
tree, err := ki.Parse(os.Stdin)
if err != nil {
slog.Error("parse tree", "err", err)
os.Exit(1)
}
for _, arg := range flag.Args() {
tree.Add(arg)
}
if tree.NumChildren() == 0 {
flag.Usage()
os.Exit(2)
}
printTree(tree, -1)
}