1package main
 2
 3import (
 4	"log/slog"
 5	"net/http"
 6	"os"
 7
 8	_ "net/http/pprof" // profiling
 9
10	_ "github.com/joho/godotenv/autoload" // automatically load .env files
11
12	"github.com/charmbracelet/crush/internal/cmd"
13	"github.com/charmbracelet/crush/internal/event"
14	"github.com/charmbracelet/crush/internal/log"
15)
16
17func main() {
18	defer log.RecoverPanic("main", func() {
19		event.Flush()
20		slog.Error("Application terminated due to unhandled panic")
21	})
22
23	if os.Getenv("CRUSH_PROFILE") != "" {
24		go func() {
25			slog.Info("Serving pprof at localhost:6060")
26			if httpErr := http.ListenAndServe("localhost:6060", nil); httpErr != nil {
27				slog.Error("Failed to pprof listen", "error", httpErr)
28			}
29		}()
30	}
31
32	cmd.Execute()
33}