-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
48 lines (39 loc) · 959 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
47
48
package main
import (
"fmt"
"os"
"os/signal"
"runtime"
"strings"
"syscall"
"github.com/theapemachine/amsh/cmd"
"github.com/theapemachine/errnie"
)
func main() {
errnie.Debug("Starting AMSH")
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt, syscall.SIGINT)
go func() {
<-c
fmt.Println("\nProgram interrupted! Printing stack trace:")
printStackTrace()
os.Exit(1)
}()
if err := cmd.Execute(); err != nil {
errnie.Error(err)
os.Exit(1)
}
errnie.Debug("AMSH finished")
}
func printStackTrace() {
buf := make([]byte, 1<<16) // 64KB buffer size
stackSize := runtime.Stack(buf, true)
stackTrace := string(buf[:stackSize])
// Parse and filter the stack trace for relevant lines
for _, line := range strings.Split(stackTrace, "\n") {
// Print only lines containing file and line number information
if strings.Contains(line, ".go:") {
fmt.Println(line)
}
}
}