-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
46 lines (37 loc) · 786 Bytes
/
main.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
package main
import (
"flag"
"fmt"
"os"
"text/template"
"github.com/Ajnasz/i3tree/dot"
"github.com/Ajnasz/i3tree/tree"
i3ipc "github.com/ndemarinis/i3ipc-go"
)
func main() {
var printDot bool
var tplStr string
flag.BoolVar(&printDot, "dot", false, "")
flag.StringVar(&tplStr, "template", "[{{.Type}} {{.Layout}}] {{.Name}}", "template to render the node name")
flag.Parse()
ipcsocket, err := i3ipc.GetIPCSocket()
if err != nil {
fmt.Fprint(os.Stderr, err)
os.Exit(1)
}
tpl, err := template.New("node").Parse(tplStr)
if err != nil {
fmt.Fprint(os.Stderr, err)
os.Exit(1)
}
i3tree, err := ipcsocket.GetTree()
if err != nil {
fmt.Fprint(os.Stderr, err)
os.Exit(1)
}
if printDot {
dot.Print(i3tree, tpl)
} else {
tree.Print(i3tree, tpl)
}
}