forked from bcicen/ctop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
101 lines (84 loc) · 1.58 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package main
import (
"fmt"
"os"
"github.com/bcicen/ctop/config"
"github.com/bcicen/ctop/cwidgets/compact"
"github.com/bcicen/ctop/logging"
"github.com/bcicen/ctop/widgets"
ui "github.com/gizak/termui"
)
var (
build = "none"
version = "dev-build"
log *logging.CTopLogger
cursor *GridCursor
cGrid *compact.CompactGrid
header *widgets.CTopHeader
)
func main() {
readArgs()
defer panicExit()
// init ui
ui.ColorMap = ColorMap // override default colormap
if err := ui.Init(); err != nil {
panic(err)
}
defer ui.Close()
// init global config
config.Init()
// init logger
log = logging.Init()
if config.GetSwitchVal("loggingEnabled") {
logging.StartServer()
}
// init grid, cursor, header
cursor = NewGridCursor()
cGrid = compact.NewCompactGrid()
header = widgets.NewCTopHeader()
for {
exit := Display()
if exit {
log.Notice("shutting down")
log.Exit()
return
}
}
}
func readArgs() {
if len(os.Args) < 2 {
return
}
for _, arg := range os.Args[1:] {
switch arg {
case "-v", "version":
printVersion()
os.Exit(0)
case "-h", "help":
printHelp()
os.Exit(0)
default:
fmt.Printf("invalid option or argument: \"%s\"\n", arg)
os.Exit(1)
}
}
}
func panicExit() {
if r := recover(); r != nil {
ui.Clear()
fmt.Printf("panic: %s\n", r)
os.Exit(1)
}
}
var helpMsg = `ctop - container metric viewer
usage: ctop [options]
options:
-h display this help dialog
-v output version information and exit
`
func printHelp() {
fmt.Println(helpMsg)
}
func printVersion() {
fmt.Printf("ctop version %v, build %v\n", version, build)
}