-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
59 lines (46 loc) · 1.01 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
package main
import (
"fmt"
"os"
kingpin "gopkg.in/alecthomas/kingpin.v2"
)
var (
app = kingpin.New("kpanic", "Command-line utility for diagnosing kernel panics.")
ls = app.Command("ls", "List available panics.")
show = app.Command("show", "Display panic contents.")
showName = show.Arg("name", "Kernel panic filename").
Required().
String()
last = app.Command("last", "Display last panic.")
)
func main() {
switch kingpin.MustParse(app.Parse(os.Args[1:])) {
case ls.FullCommand():
panics, err := listPanics(diagnosticsFolder)
if err != nil {
panic(err)
}
for _, p := range panics {
fmt.Println(p)
}
case show.FullCommand():
err := displayPanic(*showName)
if err != nil {
panic(err)
}
case last.FullCommand():
panics, err := listPanics(diagnosticsFolder)
if err != nil {
panic(err)
}
if len(panics) == 0 {
fmt.Println("No panics found")
return
}
lastPanic := panics[len(panics)-1]
err = displayPanic(lastPanic)
if err != nil {
panic(err)
}
}
}