mirror of
https://github.com/bcicen/ctop.git
synced 2025-12-06 23:26:45 +08:00
add version, help printing to main()
This commit is contained in:
74
main.go
74
main.go
@@ -12,24 +12,26 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
build = ""
|
build = "none"
|
||||||
version = "dev-build"
|
version = "dev-build"
|
||||||
|
|
||||||
log *logging.CTopLogger
|
log *logging.CTopLogger
|
||||||
cursor *GridCursor
|
cursor *GridCursor
|
||||||
cGrid = compact.NewCompactGrid()
|
cGrid *compact.CompactGrid
|
||||||
header = widgets.NewCTopHeader()
|
header *widgets.CTopHeader
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
defer func() {
|
readArgs()
|
||||||
if r := recover(); r != nil {
|
defer panicExit()
|
||||||
ui.Clear()
|
|
||||||
fmt.Printf("panic: %s\n", r)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
|
// init ui
|
||||||
|
if err := ui.Init(); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
defer ui.Close()
|
||||||
|
|
||||||
|
// init global config
|
||||||
config.Init()
|
config.Init()
|
||||||
|
|
||||||
// init logger
|
// init logger
|
||||||
@@ -38,12 +40,10 @@ func main() {
|
|||||||
logging.StartServer()
|
logging.StartServer()
|
||||||
}
|
}
|
||||||
|
|
||||||
// init ui, grid
|
// init grid, cursor, header
|
||||||
if err := ui.Init(); err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer ui.Close()
|
|
||||||
cursor = NewGridCursor()
|
cursor = NewGridCursor()
|
||||||
|
cGrid = compact.NewCompactGrid()
|
||||||
|
header = widgets.NewCTopHeader()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
exit := Display()
|
exit := Display()
|
||||||
@@ -54,3 +54,47 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user