-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
72 lines (56 loc) · 1.18 KB
/
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package main
/*
main programm
command line handling, init and passing control to
screen event loop
(c) Holger Berger 2016, under GPL
*/
import (
"os"
"strings"
"github.com/jessevdk/go-flags"
termbox "github.com/nsf/termbox-go"
)
var opts struct {
Hosts string `long:"hosts" description:"hosts files to load, comma seperated"`
}
// main programm, reading arguments
func main() {
var hosts *HostsT
// parse commandlines for --hosts option
_, err := flags.Parse(&opts)
if err != nil {
os.Exit(0)
}
if opts.Hosts != "" {
hosts = NewHosts()
for _, hf := range strings.Split(opts.Hosts, ",") {
hosts.AddFile(hf)
}
} else {
hosts = nil
}
// files holds list of files
var files []*FlexFileT
// read files from commandline
for _, filename := range os.Args[1:] {
f, err := ReadFlexFile(filename)
if err == nil {
files = append(files, f)
}
}
// create the buffer aggregating the files
buffer := NewBuffer()
buffer.AddHosts(hosts)
// add all files to buffer
for f := range files {
buffer.addFile(files[f])
}
buffer.sortFile()
// create a screen
screen := NewScreen(files, buffer)
// run the event loop
screen.eventLoop()
// cleanup
termbox.Close()
}